流行状态历史和链接



如果我单击一个简单的链接,我对这个函数有问题,这个函数是调用的,但我只需要为导航器中的上一个/下一个按钮或键盘中的按钮调用他

$(window).on("popstate", function() {
    alert('ok');
});

谢谢

尝试 onbeforeunload 事件:

window.onbeforeunload = confirmExit;
function confirmExit()
{
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
}

演示:https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm

最新更新