RossOlson.com

Error Pages: The 404 Experience

The JavaScript for the Error page is pretty simple and I have it listed here. If you have difficulty copying it off of this page, you can either open up the source code for this page and grab it or save the text file that is linked here. (Don't click on that link, just drag it to your desktop.)

Automatically move browsers from .html pages to .shtml pages

<SCRIPT LANGUAGE="JavaScript1.2">
<!--

// Script by Ross Olson
// www.ordersomewherechaos.com/rosso/

// Written for For Placement Only
// http://www.ordersomewherechaos.com/rosso/, July, 1999

	var str = location.href;
  
	if (str.search(/.html/i)) {
		location.href = str.replace(/.html/i, ".shtml");
	}

//-->
</SCRIPT>


Automatically move a bad URL to the parent directory.

<SCRIPT LANGUAGE="JavaScript"> <!-- // Script by Tomer Shiran, Doc JavaScript: // www.webreference.com/js/ // Written for the Oregon Museum of Science and Industry // http://www.omsi.edu, March 11, 1998 var str = location.href; if (str.charAt(str.length - 1) != "/") { location.href = str.substring(0, str.lastIndexOf("/") + 1); } //--> </SCRIPT>

The scripts are pretty simple just put one or the other at the head of the HTML page, in between the the HEAD tags. To see the first script in action, try this link, which points to a ".html" version of this page. After the script runs you should end up back at this page with the correct ".shtml" extension. This script could be put on an 404 error response page.

For an example of a page with the second script in use, take a look at this page (which I took with me after I left OMSI). The script will run and put your browser back up at the top of the WebDev section index. To see what happens when the script is not there, take a look at this page to see the page that shows when JavaScript is not available.



 
 

[ Read and write comments ]