0
我想在用户尝试刷新页面,导航到另一页,关闭页面时用确认对话框警告用户。当用户尝试刷新/关闭/导航到其他网页时显示确认对话框
就像Gmail一样;例如当你写东西然后尝试关闭页面而不发送消息时,会出现一个警告对话框,其中有两个选项: 离开本页面/留在此页
我想在用户尝试刷新页面,导航到另一页,关闭页面时用确认对话框警告用户。当用户尝试刷新/关闭/导航到其他网页时显示确认对话框
就像Gmail一样;例如当你写东西然后尝试关闭页面而不发送消息时,会出现一个警告对话框,其中有两个选项: 离开本页面/留在此页
使用onbeforeunload。从https://developer.mozilla.org/en/DOM/window.onbeforeunload:
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Your text';
}
// For others
return 'Your text';
};
检查此主题。 http://stackoverflow.com/questions/147636/best-way-to-detect-when-user-leaves-a-web-page – 2012-01-17 19:33:58