抱歉标题不太清晰,我会解释一下:
当用户试图离开页面时,我有一个标准的“你确定要离开”对话框:
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" />
有没有办法在IE8中继续使用window.location.href并避免这个bug?
window.location
而不是.href
吗? - Ilia G