简体   繁体   English

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

[英]Why does this not cause a browser redirect?

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?!?! 警报窗口将打开,因此条件为true ...但是浏览器不会重定向?!?!

Any thoughts? 有什么想法吗?

Depending on the browser you are using, window.location = might be not enough. 根据您使用的浏览器, window.location =可能还不够。

Try to "full qualify" with window.location.href = "http://www.google.com"; 尝试使用window.location.href = "http://www.google.com"; “完全合格window.location.href = "http://www.google.com";

However, there is zero jQueryfication in that code :-) 但是,该代码中的jQueryfication为零:-)

window.location.href

是您要寻找的

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. 确保在浏览器重定向之前先看到此警报,否则,如果条件返回false。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 clearInterval是否会导致重定向? - Does clearInterval cause redirect? 为什么这会导致浏览器锁定(我认为是无限循环) - Why does this cause a browser lock(infinite loop I presume) 为什么<! - <script>会导致浏览器中的DOM树中断? - Why does <!--<script> cause a DOM tree break on the browser? Django + Ajax:为什么它会重定向到新的 URL 并在浏览器上呈现响应? - Django + Ajax: why does it redirect to a new URL and renders the response on browser? 为什么在Firefox或Chrome中重新加载页面会导致浏览器调用服务器后触发卸载事件处理程序? - Why does reloading page in Firefox or Chrome cause the unload event handler to trigger after the browser calls the server? 当浏览器控制台未打开时,为什么要求在Internet Explorer 9中导致超时? - Why does require cause a timeout in Internet Explorer 9 when the browser console isn’t open? 为什么browser.wait会导致量角器无条件地等待异步任务 - Why does browser.wait cause protractor to wait indefinetely for an async task 为什么 TypeScript 转译到 target: ES5, Module: CommonJS 会导致浏览器出错? - Why does TypeScript transpilation to target: ES5, Module: CommonJS cause errors in the browser? 回击浏览器以返回反应页面不会导致页面上的任何代码运行 - 为什么? - Hitting back on browser to return to a react page does not cause any code on the page to run - why? 为什么这不会引起无限循环? - Why does this not cause an infinite loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM