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:

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

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:

var allowedreferrer = "http://www.yoursite.com/referringpagename.htm"; 
if (document.referrer.indexOf(allowedreferrer) == -1) {
alert("You can only access this page from " + allowedreferrer);

Leave a Comment

You must be logged in to post a comment.