gpt4 book ai didi

javascript - onbeforeunload 对话框取消与 window.location.href IE8 错误

转载 作者:数据小太阳 更新时间:2023-10-29 04:16:15 25 4
gpt4 key购买 nike

抱歉标题晦涩难懂,希望我能解释一下:

我有一个标准的“您确定要离开吗”对话框,当用户试图离开页面时会弹出该对话框:

window.onbeforeunload = function() {
return 'You have unsaved changes';
}

当它与 window.location.href 和用户点击取消 结合使用时,Internet Explorer 8 或更早版本会抛出“未指定错误”。其他现代浏览器似乎不会发生同样的情况。

<script type="text/javascript">
$('input').click(function() {
window.location.href = 'http://www.google.com'; // error is thrown here
});
</script>

<input type="button" value="Go to google" />

有什么方法可以继续使用 window.location.href 并解决 IE8 中的这个错误?

最佳答案

这是一个已知的 IE 错误。我认为您可以使用 try block 捕获该错误。

关于javascript - onbeforeunload 对话框取消与 window.location.href IE8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8264566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com