473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using javascript to determine if file exists on host site

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
Jul 20 '05 #1
3 10364

"Daniel Borden" <db******@nycap.rr.com> schreef in bericht
news:V1*******************@twister.nyroc.rr.com...
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

Jul 20 '05 #2

In article <V1*******************@twister.nyroc.rr.com>,
"Daniel Borden" <db******@nycap.rr.com> writes:
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
--

Warren S. Sarle SAS Institute Inc. The opinions expressed here
sa****@unx.sas.com SAS Campus Drive are mine and not necessarily
(919) 677-8000 Cary, NC 27513, USA those of SAS Institute.
Jul 20 '05 #3
Daniel Borden wrote:
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/cor...#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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: OvErboRed | last post by:
Hi, I'm trying to determine whether a given URL exists. I'm new to Python but I think that urllib is the tool for the job. However, if I give it a non-existent file, it simply returns the 404 page....
26
by: Don | last post by:
I'm writing an html page with some JavaScript that reads a web page into a client-side temp file, then reformats it, then submits that same file as a URL to the browser for display, via...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
2
by: Wayne Wengert | last post by:
I am trying to determine if a file exists on a web site but I cannot get a match. I have verified that the file does exists in the specified directory (I verified the case of the file and directory...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.