Using javascript to determine if file exists on host site

D

Daniel Borden

Big hello to my fellow programmers - I'm new to javascript and PHP and I am
wondering if there is a method or function to capture a 404 error in the
event a particular html file cannot be found. I want to redirect that error
to another page or design the code to send me an email telling me what page
was selected and not found. In other languages I can trap such an error and
respond to it.

Thanks,
Dan
 
J

Janwillem Borleffs

Daniel Borden said:
Big hello to my fellow programmers - I'm new to javascript and PHP and I am
wondering if there is a method or function to capture a 404 error in the
event a particular html file cannot be found. I want to redirect that error
to another page or design the code to send me an email telling me what page
was selected and not found. In other languages I can trap such an error and
respond to it.

Just use Apache's ErrorDocument directive (or equal when you are not using
Apache).


JW
 
G

Grant Wagner

Daniel said:
Big hello to my fellow programmers - I'm new to javascript and PHP and I am
wondering if there is a method or function to capture a 404 error in the
event a particular html file cannot be found. I want to redirect that error
to another page or design the code to send me an email telling me what page
was selected and not found. In other languages I can trap such an error and
respond to it.

Thanks,
Dan

This would not be a client-side JavaScript or a server-JavaScript or PHP issue
(well, not directly).

Configure your web server to go to a custom 404 response page, then that 404
response page can execute any server-side code of your choice to do whatever
you want it to do. How you do this is server dependant, in apache, you use the
ErrorDocument directive: <url:
http://httpd.apache.org/docs/mod/core.html#errordocument />. ErrorDocument can
be specified site wide, or just for a specific directory, it can also be
changed dynamically by adding it to/changing it in a .htaccess file in a
directory.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
W

Warren Sarle

Big hello to my fellow programmers - I'm new to javascript and PHP and I am
wondering if there is a method or function to capture a 404 error in the
event a particular html file cannot be found. I want to redirect that error
to another page or design the code to send me an email telling me what page
was selected and not found. In other languages I can trap such an error and
respond to it.

This is very simple in PHP. There are several functions that
will tell whether a file exists and is readable on your server
or another server. For example, you could start with
http://www.php.net/manual/en/function.is-readable.php
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top