我需要在用户离开页面之前警告他们未保存的更改(这是一个非常常见的问题).
window.onbeforeunload = handler
这是可行的,但它会弹出一个默认对话框,其中包含一条令人讨厌的标准消息,其中包含我自己的文本.我需要完全替换标准消息,使我的文本清晰,或者(更好的)使用jQuery使用模式对话框替换整个对话框.
到目前为止,我失败了,我还没有找到其他似乎有答案的人.这有可能吗?
我的页面中的Javascript:
<script type="text/javascript">
window.onbeforeunload = closeIt;
</script>
函数的作用是:
function closeIt()
{
if (changes == "true" || files == "true")
{
return "Here you can append a custom message to the default dialog.";
}
}
使用jQuery和jqModal,我try 了这种方式(使用自定义确认对话框):
$(window).beforeunload(function () {
confirm('new message: ' + this.href + ' !', this.href);
return false;
});
这也不起作用——我似乎无法参加beforeunload
项赛事.