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;

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 powered by Disqus

Recent Files


Recent Dev-Articles

Read recently