admin管理员组文章数量:1356904
I have tried using the following script
[if IE]
<script type="text/javascript">
window.location = "error.html";
</script>
[endif]
It works like a treat apart from the fact that other browsers such as Chrome are also redirecting to the error.html page. What is wrong with it? Thanks
I have tried using the following script
[if IE]
<script type="text/javascript">
window.location = "error.html";
</script>
[endif]
It works like a treat apart from the fact that other browsers such as Chrome are also redirecting to the error.html page. What is wrong with it? Thanks
Share Improve this question asked Oct 7, 2014 at 14:13 TomTom 4461 gold badge6 silver badges14 bronze badges 2- msdn.microsoft./en-us/library/ms537512(v=vs.85).aspx – j08691 Commented Oct 7, 2014 at 14:16
- 2 Don't. Seriously. If people want to use IE, especially modern IE. Let them. Use feature detection and progressive enhancement instead. – Quentin Commented Oct 7, 2014 at 14:19
4 Answers
Reset to default 6Try this:
<script type="text/javascript">
if(navigator.appName.indexOf("Internet Explorer")!=-1 || navigator.userAgent.match(/Trident.*rv[ :]*11\./))
{
//This user uses Internet Explorer
window.location = "error.html";
}
</script>
Greetings from Vienna
I know there have been answers all around, but here is in my opinion the most plete answer..
HTML
<p>Is this internet explorer?<p>
<p id="ie"></p>
And now the JavaScript
if(detectIE()){
document.getElementById("ie").innerHTML = "Yes it is!";
} else {
document.getElementById("ie").innerHTML = "No it's not!";
}
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
return true;
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
return true;
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
return true;
}
// other browser
return false;
}
Working example: https://codepen.io/gerritman123/pen/VjrONQ
You need to use conditional ments.
Keep in mind though, IE10+ does not respect these conditional ments and will treat them the same way Firefox and Chrome does.
<!--[if IE]>
<script type="text/javascript">
window.location = "error.html";
</script>
<![endif]-->
Try this:
if (window.navigator.userAgent.indexOf("MSIE ") > 0)
window.location="error.html";
本文标签: javascriptHow to redirect Internet Explorer users to a new pageStack Overflow
版权声明:本文标题:javascript - How to redirect Internet Explorer users to a new page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744024176a2577749.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论