防止IE9中的onbeforeunload对话框 [英] Preventing onbeforeunload dialogs in IE9
问题描述
我在IE9中遇到了onbeforeunload问题-运行以下代码时,它反复出现一个对话框,询问您是否要保留或离开该页面.
I'm having an issue in IE9 with onbeforeunload -- when the code below is run it repeatedly brings up a dialog asking if you want to stay or leave the page.
我基于此线程无济于事.
在此方面的任何帮助将不胜感激.
Any help on this would be much appreciated.
代码示例:
window.onbeforeunload = function(e) {
e.preventDefault();
e.returnValue = false;
saveFormData();
return null;
}
function saveFormData() {
$.post("<?php echo site_url('resume/cleanup'); ?>", { resume_id: "<?php echo $this->session->userdata('resume_id'); ?>" } );
}
推荐答案
由于大多数浏览器会阻止该页面,因此您无法在页面卸载时发送AJAX请求.您应该要求用户留在页面上,如果有脏数据.这就是您应该在onbeforeunload
处理程序
You cannot send an AJAX request while the page is unloading as most browsers block it. You should ask the user to stay on the page if there is dirty data. That's all you should do from your onbeforeunload
handler
在不调用$ .post的情况下尝试您的代码,它的行为应与预期的一样
Try your code without calling $.post and it should behave as expected
这篇关于防止IE9中的onbeforeunload对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!