对于这个不起眼的标题感到抱歉,希望我能解释一下:
我有一个标准,"你确定要离开"对话框,当用户试图离开页面时弹出对话框:
window.onbeforeunload = function() {
return 'You have unsaved changes';
}
Run Code Online (Sandbox Code Playgroud)
如果与此相关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" />
Run Code Online (Sandbox Code Playgroud)
有什么方法可以继续使用window.location.href并解决IE8中的这个错误吗?