Javascript IE 中的 window.location 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6297291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:09:27  来源:igfitidea点击:

window.location Problem in IE

javascriptinternet-explorer

提问by DiegoP.

I have this simple code that is working fine in every browser, but NOT in IE (every version).

我有这个简单的代码,它在每个浏览器中都可以正常工作,但在 IE(每个版本)中都没有。

 window.setTimeout('window.location = \"http://www.domain/modules/yobilab/copyright/classes/GO_overview.php?refNumb=".$RefNumb."\"', 3000);
            return false;

In every browser it will go to the right link

在每个浏览器中,它将转到正确的链接

In IE instead it includes also the Link where it comes from, so it will become something like this:

在 IE 中,它也包括它来自的链接,所以它会变成这样:

http://www.domain/PAGEWHEREIWAS/modules/yobilab/copyright/classes/GO_overview.php?refNumb=something

Why it is doing so?

为什么要这样做?

It generates a NOT FOUND error obviously.

显然,它会生成 NOT FOUND 错误。

回答by Teddy

Try using document.locationinstead of window.location.

尝试使用document.location代替window.location.

回答by Candide

You need to create an anonymous function:

您需要创建一个匿名函数:

setTimeout(function() {window.location = "http://www.domain/modules/yobilab/copyright/classes/GO_overview.php?refNumb=12"}, 3000);

回答by Hellbent

Add a "/" before the link, this makes IE understand that it is a relative link and forces the correct redirect.

在链接前加一个“/”,这让 IE 理解它是一个相对链接并强制正确重定向。

回答by The Mask

function redirect() { 
     window.location.href = "http://www.domain/PAGEWHEREIWAS/modules/yobilab/copyright/classes/GO_overview.phprefNumb=something"; 

}

setTimeout(redirect, 3000);