Popstate的历史和链接

时间:2015-03-13 22:58:53

标签: javascript

我有这个功能的问题,如果我点击一个简单的链接这个功能是呼叫,但我需要打电话给他只是导航器中的上一个/下一个按钮或键盘上的按钮

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

由于

1 个答案:

答案 0 :(得分:0)

尝试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?";
}

在这里演示:http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm