Latch Referrer

[Total: 0    Average: 0/5]

This example will detect the referrer (outside your site) and put that into a cookie

Head Code:

<script src="http://www.js-examples.com/bin/cookies.js"></script>
<script>
var myCookie = new Cookie(document,"secretname",0); // cookie is non-persistent
if (document.referrer.indexOf("js-examples") == -1) {
  // this referrer is from off site
  myCookie.referrer = document.referrer;
  myCookie.write();
}
myCookie.read();
var REF = myCookie.referrer || "no referrer page";
</script>

Body Code:

<script>
var _a = '';
if(REF=="no referrer page")
    _a += REF;
else
    _a += '<a href="'+REF+'">'+REF+'</a>';
document.write(_a);
</script>

Times Viewed: 6

Leave a Reply

Your email address will not be published. Required fields are marked *