Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

javascript - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...