开发者

Is there any case where window.location will not work in a browser? (except js turned-off)

开发者 https://www.devze.com 2023-02-09 03:42 出处:网络
I\'m wondering if there is any case where window.location will not work? I was thinking maybe some older IE browsers don\'t let the javascript redirect t开发者_开发知识库he page due to some random se

I'm wondering if there is any case where window.location will not work?

I was thinking maybe some older IE browsers don't let the javascript redirect t开发者_开发知识库he page due to some random security restriction?

Does anyone know if there is any browser/situation where window.location = "url" will fail?


No. It should work in all JS enabled browsers.

window.location = 'http://example.com';

How are you going to use it? If it is some odd way of using it then it might not work in IE.


If the redirect is inside an iframe then the main page will not redirect. This is expected though.


If there is an error elsewhere in your code:

window.location="http://www.google.com";
alert("error);

The missing " in the alert statement will prevent execution of all code by the JS engine.

0

精彩评论

暂无评论...
验证码 换一张
取 消