Forum Moderators: open

Message Too Old, No Replies

document.referrer inside a form

document.referrer

         

NCTFleetlist

8:44 pm on Feb 13, 2011 (gmt 0)

10+ Year Member



Hello people

I have custom error pages and on the 404 page I have included a form for the user to post me a message telling me of the problem...

I want to include the script document.referrer as part of the form and from weeks of trying the only way I have found of getting this to work is by putting document.referrer inside a function, then calling that function from onFocus within a text box.

However, as you can see from my example when the function is called, it displays in what appears as a new page.

My aim is simply to have the script display the referring page inside the textbox so that when the form is submitted I get to know where the dead link came from.

Hope you can help.

this is the code I am using
<script type="text/javascript"> 
function fnTest()
{
document.write(document.referrer)
}
</script>


Your Previous Page: <input type="text" value="" width="20" onFocus="fnTest()" >



site link:
[nctfleetlist.co.uk ]

Fotiman

9:51 pm on Feb 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!
You can't call document.write after the page loads (it will replace the current document).

<input type="hidden" value="" id="ref">

And then just before your closing </body> tag:

<script>
document.getElementById('ref').value = document.referrer;
</script>

NCTFleetlist

10:22 pm on Feb 13, 2011 (gmt 0)

10+ Year Member



Thank you very much for your help and time, it worked a treat!


really is appreciated