5

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

var url = myurl +'?id=' + id + '&phase=' + phase;
window.location = url;

使用 IE 开发工具栏,我验证了 url 具有有效的 url,并且 window.location 返回了新的 url...唯一的问题是页面没有重新加载。

有谁知道 window.location 现在在分配新文档时实际加载新文档的任何原因?

4

5 回答 5

13

改为使用window.location.href = url;

于 2011-07-20T15:17:42.597 回答
4

您的 JavaScript 是否从 <input> type=" button " 或 type=" submit " 运行 onclick 事件?

如果您的按钮是 type="submit" ,除非您停止执行提交,否则它将不起作用。

我知道这很明显,但我没有在其他评论中看到这一点,所以我可能只是添加到这个线程中。

于 2013-11-01T14:17:09.120 回答
1

所以我今天也遇到了同样的错误,由于某种原因,我无法让我的页面重定向到谷歌(仅用于测试目的)。直接从另一个站点复制代码并且它可以工作,所以我再次尝试了 google.com - 低并且看它没有工作......

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

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

此内容无法在框架中显示

 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.

我用来得到的代码:

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

看起来浏览器没有显示这个错误,而是他们只是不重定向你......有点令人困惑:/

于 2012-05-05T22:33:38.627 回答
0

我正在使用 jquery,并且出现了类似的问题,我必须通过将data-ajax=false属性添加到<a href="...链接来解决它。

于 2013-07-07T23:59:18.653 回答
-1

感谢@Senad Meskin

document.location = url;

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

于 2011-07-20T15:19:47.260 回答