即使在Chrome上重定向了URL,jQuery仍继续运行 [英] Jquery continues running even after URL redirect on Chrome

查看:85
本文介绍了即使在Chrome上重定向了URL,jQuery仍继续运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('#target').click(function() {
window.location.replace("http://www.google.com");
return false;
}); 

我如何告诉chrome和所有其他浏览器停止正在执行的操作并立即重定向到另一个网页?

Firefox 8.0根据需要立即执行window.location.replace.

当我逐步执行以上代码时,Chrome 15.0.874.121飞过window.location代码并返回false,然后移至后续的Jquery函数(换句话说,Chrome完成了整个调用堆栈,然后替换了URL )

我正在尝试在多个不同的区域中执行重定向,最大的问题是额外的Jquery可以为重定向增加3-5秒的时间,尤其是在.ajax成功调用中.

我正在使用jQuery 1.7.1,并且没有javascript错误

我尝试过:

  • 到处都说"return false"
  • 使用不同的重定向(location.reload(true),location.href等)
  • 将重定向一直移到其他任何功能之外
  • 将重定向重定向到一个单独的功能

无论我做什么,Chrome都拒绝简单地转到另一个网站而无需先完成其调用堆栈.请帮忙.

解决方案

$('#target').click(function() {
window.location.replace("http://www.google.com");
//THROW an exception is the only solution I've found so far
throw "Reloading Page";
}); 

不幸的是,我没有找到更好的答案.毕竟这不是jquery的问题.我已将所有内容整理整齐:删除了chrome中的所有扩展名,删除了所有外部文件,制作了一个完全空白的.html文件,仅包含最少的javascript和一个简单的onclick ...,然后Chrome仍然通过重定向进行了爆炸.

SO:到目前为止,我唯一的答案是抛出一个异常,告诉Chrome在重定向后立即停止运行JS.

感谢 Gijs

不幸的是,默认情况下,Chrome会在抛出异常的情况下暂停,因此实际上并不是一个可部署的解决方案.

$('#target').click(function() {
window.location.replace("http://www.google.com");
return false;
}); 

How can I tell chrome and all other browsers to stop what they're doing and immediately redirect to another web page?

Firefox 8.0 executes the window.location.replace immediately, as I want it to.

When I step through the code above, Chrome 15.0.874.121 flies right past the window.location code and the return false and then moves into subsequent Jquery functions (in other words, Chrome completes the entire call stack and THEN replaces the URL)

I'm trying to execute the redirect in a number of different areas, the biggest problem is that the additional Jquery can add 3-5 SECONDS of time to the redirects, especially from within an .ajax success call.

I'm using jQuery 1.7.1 and have no javascript errors

I've tried:

  • putting 'return false' everywhere
  • using different redirects (location.reload(true), location.href, etc)
  • moving my redirect all the way outside of any other function
  • Moving my redirect to a separate function altogether

No matter what I do, Chrome refuses to simply GO to another web site without finishing its call stack first. Please help.

解决方案

$('#target').click(function() {
window.location.replace("http://www.google.com");
//THROW an exception is the only solution I've found so far
throw "Reloading Page";
}); 

Unfortunately, I have not found a better answer. It is NOT a jquery issue after all. I've trimmed everything down: removed all extensions in chrome, removed all external files, made a completely blank .html file with bare minimum javascript and a simple onclick... and Chrome STILL blasted through the redirect.

SO: As of now, my only answer is to throw an exception to tell Chrome to stop running JS just after the redirect.

Thanks to Gijs

Edit: Unfortunately, Chrome pauses on thrown exceptions be default so this turns out to not actually be a deployable solution.

这篇关于即使在Chrome上重定向了URL,jQuery仍继续运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆