大佬教程收集整理的这篇文章主要介绍了html – IE中的window.onbeforeunload和window.location.href,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
window.onbeforeunload = confirmBeforeClose; function confirmBeforeClose() { if (jwd.global.inEditModE) return "Your changes will not be saved :) and you will be punished to death"; }
在有未保存更改的地方,我尝试使用window.LOCATIOn.href来导航用户,我收到警报消息.
如果我在弹出窗口中单击“确定”,它可以正常工作.但是,如果我单击CANCEL,JS会在window.LOCATIOn.href中抛出一个未指定的错误.
任何帮助表示赞赏.
我能找到的唯一解决方案是在try / catch块中包装window.LOCATIOn.href调用.
以下是重现问题的完整示例.如果您取消注释try / catch,那么它在所有浏览器中都可以正常工作.
JavaScript(HTML头文件):
window.onbeforeunload = confirmBeforeClose; function confirmBeforeClose( ) { return 'You have made changes on this page that will be lost if you navigate away without saving.'; } function leavePage( ) { // try { window.LOCATIOn.href = "http://www.example.com"; // } catch( e ) { } }
HTML:
<body> <a href="#" onclick="leavePage(); return false;">Leave this page</a> </body>
以上是大佬教程为你收集整理的html – IE中的window.onbeforeunload和window.location.href全部内容,希望文章能够帮你解决html – IE中的window.onbeforeunload和window.location.href所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。