改写问题——
我正在尝试制作一个页面,如果用户离开该页面(到其他链接/网站或关闭窗口/选项卡),我想显示处理onbeforeunload
程序说we have a great offer for you?
,如果用户选择leave the page
它应该进行正常传播,但如果他选择stay on the page
我需要他将其重定向到提供页面redirection is important, no compromise
。为了测试让我们重定向到google.com
我做了一个程序如下 -
var stayonthis = true;
var a;
function load() {
window.onbeforeunload = function(e) {
if(stayonthis){
a = setTimeout('window.location.href="http://google.com";',100);
stayonthis = false;
return "Do you really want to leave now?";
}
else {
clearTimeout(a);
}
};
window.onunload = function(e) {
clearTimeout(a);
};
}
window.onload = load;
但问题是如果他点击链接yahoo.com
并选择leave the page
他不会去雅虎而是去谷歌:(
帮我 !!提前致谢