为什么 window.location 无法加载新页面?

发布于 2024-11-25 01:05:17 字数 266 浏览 0 评论 0原文

这段代码过去可以工作,但现在不行了:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最舍不得你 2024-12-02 01:05:18

我正在使用 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.

忘你却要生生世世 2024-12-02 01:05:18

感谢 @Senad Meskin

document.location = url;

为我工作。窗口停止工作的任何原因?

Thanks to @Senad Meskin.

document.location = url;

worked for me. Any reason why window would stop working?

暮年慕年 2024-12-02 01:05:17

请改用 window.location.href = url;

Use window.location.href = url; instead.

最舍不得你 2024-12-02 01:05:17

您的 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.

审判长 2024-12-02 01:05:17

所以我今天刚刚遇到同样的错误,由于某种原因我无法将我的页面重定向到谷歌(仅用于测试目的)。直接从另一个网站复制代码并且它起作用了,所以我再次尝试了 google.com - 低,结果发现它不起作用...

我还应该提到我正在尝试重定向 iframe 中的页面,而不是整个页面网页。

所以我启动了我信任的 Max's HTML Beauty++ 2004 并在其中打开了我的页面,果然它给了我错误:

该内容无法在框架中显示

 帮助保护您在此输入的信息的安全  
 网站,该内容的发布者不允许
 显示在框架中。

我用来获取的代码:

window.location = "http://www.google.com";  

看起来浏览器不会显示此错误,相反,它们只是不会重定向您...有点令人困惑:/

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:

This content cannot be displayed in a frame

 To help protect the security of information you enter into this  
 website, the publisher of this content does not allow it to be
 displayed in a frame.

The code i Used to get that:

window.location = "http://www.google.com";  

It looks like browsers don't display this error, instead they just don't redirect you... Kind of confusing :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文