为什么 window.location 无法加载新页面?
这段代码过去可以工作,但现在不行了:
var url = myurl +'?id=' + id + '&phase=' + phase;
window.location = url;
使用 IE 开发工具栏,我已经验证了 url 具有有效的 url,并且 window.location 返回新的 url...唯一的问题是页面不重新加载。
有谁知道 window.location 现在在分配新文档时实际加载新文档的任何原因?
This bit of code used to work, and now it doesn't:
var url = myurl +'?id=' + id + '&phase=' + phase;
window.location = url;
Using the IE dev toolbar I've verified that url has a valid url, and window.location returns the new url...the only problem is the page does not reload.
Does anyone know of any reasons for window.location to now actually load a new document when it is assigned to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我正在使用 jquery,出现了类似的问题,我必须通过将
data-ajax=false
属性添加到I was using jquery, and a similar problem cropped up and I had to resolve it by adding the
data-ajax=false
attribute to the<a href="...
link.感谢 @Senad Meskin。
为我工作。窗口停止工作的任何原因?
Thanks to @Senad Meskin.
worked for me. Any reason why window would stop working?
请改用
window.location.href = url;
。Use
window.location.href = url;
instead.您的 JavaScript 是否从 运行 onclick 事件? type="按钮"还是type="提交"?
如果您的按钮是 type="submit" ,除非您停止执行提交,否则它将不起作用。
我知道这很明显,但我在其他评论中没有看到这一点,所以我可能只是添加到这个线程中。
Is your JavaScript running the onclick event from an <input> type="button" or type="submit"?
If your button is type="submit" it won't work unless you stop the submission from executing.
I know this is kind of obvious but I didn't see this in the other comments so I might just add to this thread.
所以我今天刚刚遇到同样的错误,由于某种原因我无法将我的页面重定向到谷歌(仅用于测试目的)。直接从另一个网站复制代码并且它起作用了,所以我再次尝试了 google.com - 低,结果发现它不起作用...
我还应该提到我正在尝试重定向 iframe 中的页面,而不是整个页面网页。
所以我启动了我信任的 Max's HTML Beauty++ 2004 并在其中打开了我的页面,果然它给了我错误:
我用来获取的代码:
看起来浏览器不会显示此错误,相反,它们只是不会重定向您...有点令人困惑:/
So i just got this same error today, I for some reason couldn't get my page to redirect to google (just for testing purposes). Copied the code directly from another site and it worked, so i tried google.com again - low and behold it didn't work...
I should also mention that i'm trying to redirect a page in an iframe, not the entire webpage.
So I fired up my trusty Max's HTML Beauty++ 2004 and opened my page in that, sure enough it gave me my error:
The code i Used to get that:
It looks like browsers don't display this error, instead they just don't redirect you... Kind of confusing :/