...

View Full Version : Trouble setting document.referrer from Firefox



segalsegal
01-21-2009, 06:07 PM
I need to get document.referrer specified in order to have visits from our site recognized on another site. The problem is that our links are in a Java applet that pops up new browser windows. As a result, the destination site gets blank document.referrer information.

With Internet Explorer the workaround is simple because one can use a re-direct page that gets the destination URL specified in the query string and triggered by onload it extracts the destination URL and uses click() to go to it, thus setting the re-direct page as the referrer.

With Firefox this doesn't work, apparently because click() is disabled for security reasons.

Is there some way to get document.referrer information set? The best I've been able to do so far is have code that works as desired for Internet Explorer and refers to a different page for Firefox users, where the user needs to click a browser button explicitly to get to the destination site.

Is there some way to get this working without the user having to click a button?

The code that works for Internet Explorer and refers to another page for Firefox is:

<html>
<head>
<SCRIPT>
function clickTo()
{
document.links[0].href=document.location.search.substring(1);
document.links[0].click();
}
</SCRIPT>
</head>
<body onload="clickTo();">
<script>
if (navigator.appName.indexOf("Microsoft") < 0) location.replace("button.html" + document.location.search);
</script>
<form>
<a href="something.html"><input type=hidden onclick="clickTo();"></a>
</form>
</body>
</html>

itsallkizza
01-21-2009, 07:23 PM
You should be passing a tracking variable. document.referrer is an outdated and as you can see, an unreliable, method of tracking.

segalsegal
01-21-2009, 10:18 PM
You should be passing a tracking variable. document.referrer is an outdated and as you can see, an unreliable, method of tracking.By "tracking variable" do you mean something like a variable that I pass in the query string? That was my backup plan, but the folks who run the other site sound like they typically do tracking using document.referrer.

itsallkizza
01-22-2009, 12:22 AM
URL appendation is the most common way, especially if you're using some sort of tracking software (or they are).

segalsegal
01-23-2009, 06:54 PM
I found that Firefox and Internet Explorer treat referrer information after "location.replace" differently, so the following code seem to work for referring seamlessly and adding referrer information in Internet Explorer, Firefox, Safari and Chrome.

<html><head>
<SCRIPT>
function clickTo()
{
document.links[0].href=document.location.search.substring(1);
document.links[0].click();
}
</SCRIPT>
</head>
<body onload="clickTo();">
<script>
if (navigator.appName.indexOf("Microsoft") < 0) location.replace(location.search.substring(1));
</script>
<form>
<a href="Location.html"><input type=hidden onclick="clickTo();"></a>
</form>
</body></html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum