I need to warn users about unsaved changes before they leave a page (a pretty common problem).(我需要在用户离开页面之前警告用户有关未保存的更改(这是一个非常常见的问题)。)
window.onbeforeunload=handler
This works but it raises a default dialog with an irritating standard message that wraps my own text.(这可以工作,但是会引发一个默认对话框,其中包含包装我自己的文本的刺激性标准消息。) I need to either completely replace the standard message, so my text is clear, or (even better) replace the entire dialog with a modal dialog using jQuery.(我需要完全替换标准消息,以使文本清晰,或者(甚至更好)使用jQuery将整个对话框替换为模式对话框。)
So far I have failed and I haven't found anyone else who seems to have an answer.(到目前为止,我失败了,但是我还没有找到似乎有答案的其他人。) Is it even possible?(可能吗?)
Javascript in my page:(我页面中的Javascript:)
<script type="text/javascript">
window.onbeforeunload=closeIt;
</script>
The closeIt() function:(closeIt()函数:)
function closeIt()
{
if (changes == "true" || files == "true")
{
return "Here you can append a custom message to the default dialog.";
}
}
Using jQuery and jqModal I have tried this kind of thing (using a custom confirm dialog):(我使用jQuery和jqModal尝试了这种事情(使用自定义确认对话框):)
$(window).beforeunload(function() {
confirm('new message: ' + this.href + ' !', this.href);
return false;
});
which also doesn't work - I cannot seem to bind to the beforeunload event.(这也行不通-我似乎无法绑定到beforeunload事件。)
ask by flesh translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…