javascript中来自302的代码重定向

javascript中来自302的代码重定向,javascript,Javascript,这段代码在Google Chrome中有效,但在IE和Firefox中无效。 网站“somesite.org”向我发送302(重定向)。 当它从特定站点(somesite.org)转到我站点中的特定文件时,我想重定向 代码: 这应该行得通 var url = document.referrer; if(url.indexOf("somesite.org") > -1 ){ window.location = "http://forthisfile.com/this.

这段代码在Google Chrome中有效,但在IE和Firefox中无效。 网站“somesite.org”向我发送302(重定向)。 当它从特定站点(somesite.org)转到我站点中的特定文件时,我想重定向

代码:

这应该行得通

var url = document.referrer;

    if(url.indexOf("somesite.org") > -1 ){

      window.location = "http://forthisfile.com/this.html" ;
    }

IE不支持任何形式的包含,请参阅

也就是说,另一种方法是检查哈希:

if(window.location.hash.indexOf("?") >= 0) {
    ...
}
因此,在你的情况下:

  if(window.location.hash.indexOf("somesite.org") > -1 ){

      window.location = "http://forthisfile.com/this.html" ;
    }

请参阅:IE未设置document.Referer StackOverFlow:也仅适用于Chrome。IE、firefox和edge中没有任何内容。@BRS,我试过firefox。它正在按预期工作。你看到过任何具体的错误吗?如果一个站点有重定向,我不能将它发送到一个特定的页面,只使用谷歌浏览器。如果它是一个链接,那么所有浏览器都可以使用这两种代码。没有具体的错误。对不起,IE中我有这个错误:对象不支持属性或方法'includes'@BRS,在这种情况下,您可能需要尝试'indexOf'属性。更新了相同的答案。在Chrome中运行良好,与之前在IE和Firefox中一样。我看到IE和Firefox中的referer是空白的,与chrome不同。
  if(window.location.hash.indexOf("somesite.org") > -1 ){

      window.location = "http://forthisfile.com/this.html" ;
    }