web blazonry web development scripts and tutorials Get best price on Prepaid Samsung Galaxy A10e
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   

Javascript Home

image scripts
  Image Load Order
  Mouse Overs

JavaScript Resources
  Free JavaScript Books(new)
  Recommended Sites
  Bestselling Books

Bookmark and Share

JavaScript: Emailing 404 Error Information

Use JavaScript to create helpful, dynamic 404 error pages.

When someone tries to go to a page that does not exist, they get a “404 error.” 404 is the HTTP server code for file not found. The server displays an error message which is just HTML that can be customized into something useful.

A helpful 404 page displays the link that is broken and the referring document (the page the visitor came from). It could also provide a link to an email address where this info was the subject line of an email to myself.

Gathering the Location and Referrer Info
Use JavaScript to gather the information. We use two document properties: location and referrer (cgi programmers note the proper spelling). location is the URL of the page you are currently on. This displays as the broken link because that is the page you are trying to request from the server. referrer is the URL of the page you just came from.

The JavaScript for location and referrer:

<script language="JavaScript">
loc = document.location.href;
ref = document.referrer;

document.write("<p><b>Broken Link:</b> "+loc+"</p>");
document.write("<p><b>Referring Document:</b> "+ref+"</p>");

Using this page as an example (as though this were the broken link), we would display the following on the error page:

Emailing the 404 Page Information
I could have a server-side script automatically email the information about each 404 error. However, I don’t want an email for every broken link on my site. Plus, they may or may not be legitimately broken links. If I require the user to send me the link, I will get fewer emails, and the emails would provide helpful information so I could do something about the problem.

Use a simple mailto: to send the link and provide information in the detailed subject line. Do this by adding ?subject=SUBJECT LINE to the end of the mailto.

Write out the above document information to the mailto statement using JavaScript document.write function and include the above referrer and location variables.

The JavaScript for emailing the details:

<script language="JavaScript">

document.write("You can email the details to <a href='mailto:webmaster@yoursite.com?subject=404 URL: "+loc+" REFERRER: "+ref+"'>webmaster@yoursite.com</a>");


This displays:

Mouse over the link to see the info built into the link that is the subject line of the email.



Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.