Javascript Popstate历史和链接

Javascript Popstate历史和链接,javascript,Javascript,我有这个功能的问题,如果我点击一个简单的链接,这个功能是调用,但我只需要调用导航器中的上一个/下一个按钮或键盘上的按钮他 $(window).on("popstate", function() { alert('ok'); }); 谢谢尝试onbeforeunload事件: window.onbeforeunload = confirmExit; function confirmExit() { return "You have attempted to leave this

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

$(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?";
}
此处演示: