dracoblue.net

Referer with document.location is broken in Internet Explorer

When you have (this should be discussed anyways) code in your javascript application changing to a different website, you'll see something similar to that:

location.href = 'test.php';

If you want to retrieve the referer on the next page, this will not work anymore. This is a

known IE Bug and not fixed in IE 8.

For instance this in javascript:

location.href = 'test.php';

And this as test.php

echo $_SERVER['REFERER']; 

In this case, the output in IE will always be empty. In the other big browsers, it works like a charm.

But there is always, also this time, a workaround. Found at

web bugtrack.

If you use for all browsers such wrapper function:

function goto(url){
  location.href = url;
}

You just have to make it like that for the one browser:

function goto(url){
    var referLink = document.createElement('a');
    referLink.href = url;
    document.body.appendChild(referLink);
    referLink.click();
}

As you can see, it will create a link with exactly the refer link. And will properly work then.

In internet explorer, javascript by
@ 08 Jul 2009, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About