javascript 无法在 iPad 上使用 window.location

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16714578/
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-10-27 05:43:45  来源:igfitidea点击:

Use of window.location doesn't work on iPad

javascriptioswindow.location

提问by LDJ

I'm using some JavaScriptthat will redirect the user to another URLafter a fixed period of time. This is working well on all browsers but on an iPad 3 I have to test on it isn't working. The timeout fires and I call

我正在使用一些JavaScript将用户重定向到另一个URL固定时间段后。这在所有浏览器上运行良好,但在 iPad 3 上我必须测试它不起作用。超时触发,我打电话

window.location = "www.someurl.com"; 

and I've also tried

我也试过

  window.location.href = "www.someurl.com";

I can see the URLin the browser changing to www.someurl.ocombut the browser doesn't actually go there - it stays on the same page.

我可以看到URL浏览器中的 更改为 ,www.someurl.ocom但浏览器实际上并没有转到那里 - 它停留在同一页面上。

Is there something iPad specific I have to do to make this work?

有什么特定于 iPad 的我必须做的事情吗?

Thanks

谢谢

回答by Sagish

try location.href = "...", should work on both

尝试 location.href = "...",应该对两者都有效

回答by Jason

The right answer here is you are missing the protocol. window.location.href = "http://www.someurl.com";should do the trick

这里的正确答案是您缺少协议。 window.location.href = "http://www.someurl.com";应该做的伎俩