admin管理员组文章数量:1404620
I've broken my problem down to the following simple code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IE test</title>
<script src=".11.3.js"></script>
<script type="text/javascript" charset="utf-8">
$( document ).ready(function() {
$('.js-click').click(function(e){
window.location.href = '/';
});
window.onbeforeunload = function(e){
return 'moving on';
};
});
</script>
</head>
<body>
<a href="#" class="js-click">Google</a>
</body>
</html>
This works as expected in chrome without warning or error, but in IE11 it throws the following error when you choose "Stay on this Page":
File: 10.0.1.126:8080, Line: 10, Column: 11
Any idea why?
I've broken my problem down to the following simple code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IE test</title>
<script src="https://code.jquery./jquery-1.11.3.js"></script>
<script type="text/javascript" charset="utf-8">
$( document ).ready(function() {
$('.js-click').click(function(e){
window.location.href = 'http://www.google./';
});
window.onbeforeunload = function(e){
return 'moving on';
};
});
</script>
</head>
<body>
<a href="#" class="js-click">Google</a>
</body>
</html>
This works as expected in chrome without warning or error, but in IE11 it throws the following error when you choose "Stay on this Page":
File: 10.0.1.126:8080, Line: 10, Column: 11
Any idea why?
Share Improve this question asked Jul 3, 2015 at 4:47 Ricky NelsonRicky Nelson 87610 silver badges24 bronze badges 2- works fine for me in IE 11.0.9600.17842 – Arun P Johny Commented Jul 3, 2015 at 4:54
- I'm running 11.0.9600.17843. It doesn't really throw up an error dialog, but I see that message in the JavaScript console. Did you happen to look there? – Ricky Nelson Commented Jul 3, 2015 at 4:56
1 Answer
Reset to default 6Actually the error es from:
window.location.href = 'http://www.google./';
And this is just speculation, but I believe the developers of IE wanted to be able to catch when the user decides not to follow the link. Thus, you can actually try-catch this block and you'll know when the user didn't get redirected (as a result of onbeforeupload).
try {
window.location.href = 'http://www.google.';
} catch (error) {
alert("Y U NO REDIRECT");
}
If you console.log(error)
you'll see that there's no error message, and the error number is -2147467259.
本文标签: javascriptWhy does IE11 throw an error when using windowonbeforeunloadStack Overflow
版权声明:本文标题:javascript - Why does IE11 throw an error when using window.onbeforeunload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744832620a2627440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论