我已经写了一个在刷新之前警告用户的函数(出于某种原因,我需要它)。我还想实现的是,如果用户单击Leave this page,则调用另一个函数。如果用户点击stay on this page,我什么也不用做。
function warnuser()
{
return "Don't refresh the page.";
}
window.onbeforeunload = warnuser;
//if returns true call another function!谢谢。
发布于 2012-07-02 07:01:05
如果用户决定离开你不能调用函数或其他任何东西的页面,你的控制就结束了……
发布于 2013-07-18 22:54:38
function callbackExit(){
setTimeout(function(){
//User warned yet he stay on the page.
//Do your code here now.
}, 1000);
}
function warnuser()
{
callbackExit();
return "Don't refresh the page.";
}
window.onbeforeunload = warnuser;你可以像这样跟踪点击的“留在页面上”,但如果用户点击“离开站点”按钮,你仍然不能执行任何操作。
https://stackoverflow.com/questions/11286210
复制相似问题