window.onbeforeunload = function(evt) {
var message = 'Are you sure you want to leave the page. All data will be lost!';
if (typeof evt === 'undefined') {
evt = window.event;
}
if (evt && !($("#a_exit").click)) {
evt.returnValue = message;
}
return message;
};
我希望用户只能通过点击链接(具有id ="a_exit"
)离开页面。在其他情况下,如刷新页面、单击另一个链接,用户将被提示是否要离开页面。我已尝试使用上面的代码,但当我单击退出链接时仍会询问我是否要离开。
return _isSaved ? void (0) : "您在此窗口上有未保存的工作。"
- Pandi_Snkl