javascript question: grabbing the referring URL and passing it with a meta refresh

i want to code up my custom 404 error page with a javascript that will grab the referring URL (where the bad link is) and pass it to a page that will email me that link

i don't know how to grab the referrer with javascript, nor do i know how to output it on the end of the refresh URL

meta http-equiv="REFRESH" content="0; url=pagethatwillemailme.cfm?404refer=<output the referrer here>"

any help on this would be great, my javascript book doesn't cover it :(
 

how can i pass the value of that though?
this is my first time using javascript for something other then mouseovers and layers
 

AmigaMan

Diamond Member
Oct 12, 1999
3,644
1
0
I dunno really, I was just pointing out something you could try...

maybe assign it to a variable and use that for the 'url=' part of the meta tag? Or it might be a webserver setting you could set. I think that IIS has a way of setting custom error pages, maybe you could look into that?
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
with JavaScript, the referring page can be accessed by document.referrer
if you want to dynamically "write" HTML pages, you will need to use document.write. it will then replace the javascript code with whatever you ask the browser to write.

example:
<SCRIPT LANGUAGE="JavaScript" TYPE="Text/JavaScript">
<!-- hide scripts from old browser

// comments in JavaScript starts with double slash
// if you want to do something else for blank referrer, use if statements
// otherwise, the below should be enough
// don't forget not to overlap the double quotes
// if you want to write double quotes inside a double quote, use "backslash doublequote" like this: " \"blah\""
document.write ("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=pagethatwillemailme.cfm?404refer=" + document.referrer + "\"");

// and since document.referrer is meant to be a javascript object, that should be outside the
// double quotes, but still inside the list of "stuffs" to be written by document.write

// -->
</SCRIPT>
<NOSCRIPT>
<!-- this is for browsers that do not understand JavaScript -->
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=pagethatwillemailme.cfm?404refer=whateveryouwant">
</NOSCRIPT>


hope it works
good luck :)

-938-