为什么这不会导致浏览器重定向?

发布于 2024-10-24 03:22:04 字数 221 浏览 7 评论 0原文

if (selectedddItem.toString().indexOf("6ft with two") > -1) {
  window.location = "http://www.google.com/";
  alert("just passed over");
}

警报窗口打开,因此条件为真...但是浏览器不会重定向?!?!

有什么想法吗?

if (selectedddItem.toString().indexOf("6ft with two") > -1) {
  window.location = "http://www.google.com/";
  alert("just passed over");
}

The alert window opens so the condition is true... however the browser doesn't redirect?!?!

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

吲‖鸣 2024-10-31 03:22:04

根据您使用的浏览器,window.location = 可能还不够。

尝试使用 window.location.href = "http://www.google.com"; 进行“完全限定”

,但是该代码中的 jQueryfication 为零:-)

Depending on the browser you are using, window.location = might be not enough.

Try to "full qualify" with window.location.href = "http://www.google.com";

However, there is zero jQueryfication in that code :-)

丿*梦醉红颜 2024-10-31 03:22:04
window.location.href

是您正在寻找的

window.location.href

Is what you are looking for

迷迭香的记忆 2024-10-31 03:22:04

您的代码如下:

if (selectedddItem.toString().indexOf("6ft with two") > -1) {
  alert("just passed over");
  top.location.href = "http://www.google.com/";
}

确保您在浏览器重定向之前首先看到此警报,否则您的 if 条件将返回 false。

Have your code like this:

if (selectedddItem.toString().indexOf("6ft with two") > -1) {
  alert("just passed over");
  top.location.href = "http://www.google.com/";
}

Make sure you are seeing this alert first before browser redirect otherwise your if condition is returning false.

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