我有这个代码,只要他/她关闭页面,就会将用户重定向到另一个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.";
});
});
答案 0 :(得分:1)
不确定这是您要找的内容,如果他选择留在页面上,这将重定向用户:
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);
}