Isabela Cristina Isabela Cristina - 5 months ago 43
jQuery Question

Document.referrer working other pages

how to save a "session" for document.referrer?

I have two sites
site1/referer.html (this site redirect for site2).

site2/page.html (this site display a mensage when the visit is redirected from site1).

I need when user click in other page, this message keep displaying, because access came from site1, even going to other pages.

I'm using the script (referer in elseif):

facebook = /;
if (jQuery.cookie('visits') > 0.5) {
jQuery('html, body').removeAttr('style');
} else if (document.referrer && facebook.test(document.referrer)) {
var pageHeight = jQuery(document).height();
jQuery('<div id="active-popup"></div>').insertBefore('body');
jQuery('#active-popup').css("height", pageHeight);


You could just store it as a session cookie as @epascarello mentioned. The important thing here is to set the path, as the cookie wouldn't be accessible for other pages than the one that sets it (and this is what you want to do here):

jQuery.cookie('referrer', document.referrer, { path: '/' });

You can later on access this cookie with


(This is using, there is a native Javascript API (ugly) as well).