Obtaining reffering Page in javascript

Determining the reffering page is a awesome information for SEO analytic, rather then posting back to the server. Well display it, You can do so using a few lines of code, as shown here. Place the code where you want the IP address to appear:

<SCRIPT LANGUAGE="JavaScript">
var ip = '<!--#echo var="REMOTE_ADDR"-->';
document.write("Your IP address is" + ip);
</script>

Specify Referring Page

This script makes sure that your visitor can only reach a given page from the page that you specify. Paste the following before the ending head tag on the page:

<SCRIPT LANGUAGE="JavaScript">
var allowedreferrer = "http://www.yoursite.com/referringpagename.htm"; 
if (document.referrer.indexOf(allowedreferrer) == -1) {
alert("You can only access this page from " + allowedreferrer);
window.location=allowedreferrer;
}
</script>

Leave a Reply