IE 在 location.replace 之后有空的 document.referrer [英] IE has empty document.referrer after a location.replace

查看:25
本文介绍了IE 在 location.replace 之后有空的 document.referrer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站可以进行复杂的搜索并有一个加载"页面.在加载页面上我们使用:

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');">

或者:

上述两个选项的唯一区别是 location.replace() 忽略浏览器历史记录中的页面.

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

在 results_page 上,我需要阅读引荐来源网址以进行跟踪:

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

<代码><脚本>警报(文档.推荐人);</script>

这适用于除 IE 之外的所有浏览器,它返回 document.referrer 的空值.

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

有谁知道一种更好的方法来进行 javascript 重定向,它会给 IE 一个引用者的值?

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.

推荐答案

看起来这只是与 IE 用户做生意的成本.没有黑客就无法修复.现在在做一个.感谢收听.

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>

这篇关于IE 在 location.replace 之后有空的 document.referrer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆