Saturday, January 24, 2009

How to find referrer page (JavaScript)

The referrer page is the page that user loaded before loading your web page. It's useful if you are interested to find visitors of you web page came from which URL to see your web pages.

Simply enough, the referrer property of the document object, identifies the referrer page URL.

If the value of document.referrer is blank ("") , then it shows user loaded up your page directly by typing its URL into the browser address field.

Just be notified that the value of document.referrer is blank if you test an HTML page locally in your machine.

if (document.referrer != "") {
   document.writeln("Ref page: " + document.referrer);
}
else
{
   document.writeln("Page loaded up from fresh.");
}

Share/Bookmark

No comments: