Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE has empty document.referrer after a location.replace

I've got a site that does a complex search and has a "loading" page. On the loading page we use:

<body onload="window.location.replace('results_page.php');" >

Or:

<body onload="window.location = 'results_page.php';" >

The only difference between the two option above are that location.replace() ignores the page in the browser's history.

On the results_page I need to read the referrer for tracking purposes:

<script> alert(document.referrer); </script>

This works fine on all browsers except IE, which returns and empty value for document.referrer.

Anyone know a better way to do a javascript redirect that will give IE a value for the referrer?

p.s. This example has been made much more simple than it would be in production.

like image 395
mattweg Avatar asked Dec 11 '09 20:12

mattweg


People also ask

What does window location replace do?

Window location. The replace() method replaces the current document with a new one.

Does window location replace reload the page?

It's exactly the same things (currency, language, a log in) that will trigger a reload of the page.

What is a document referrer?

document. referrer gives you the URI of the page that linked to the current page. This is a value that's available for all pages, not just frames. window. parent gives you the parent frame, and its location is its URI.


1 Answers

Looks like this is just the cost of doing business with IE users. Can't be fixed without a hack. Working on one now. Thanks for listening.

http://webbugtrack.blogspot.com/2008/11/bug-421-ie-fails-to-pass-http-referer.html

I used the workaround to make this function. Works like a charm.

<script type="text/javascript" >            
function redirect(url) {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var referLink = document.createElement('a');
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    } else {
        location.href = url;
    }
}
</script>
like image 82
mattweg Avatar answered Sep 28 '22 11:09

mattweg