在Chrome上运行之前

我有这个代码,只要他/她关闭页面,就会将用户重定向到另一个URL。 这适用于Firefox,IE,Safari等,但不适用于Chrome。 它不会将用户重定向到新的URL。

谢谢!

jQuery(document).ready(function() { jQuery(window).bind('beforeunload', function(e) { location.href="http://google.com/"; return "Before you leave, please take a look at this limited time offer."; }); }); 

不确定它是你在寻找什么,如果他选择留在页面上,这将重定向用户:

DEMO

 var a,b; window.onbeforeunload = function (e) { if (b) return; a = setTimeout(function () { b = true; window.location.href = "http://google.com"; }, 500); return "Before you leave, please take a look at this limited time offer."; } window.onunload = function () { clearTimeout(a); }