[英]How to redirect Internet Explorer users to a new page?
我曾尝试使用以下脚本
[if IE]
<script type="text/javascript">
window.location = "error.html";
</script>
[endif]
除了其他浏览器(如 Chrome)也重定向到 error.html 页面这一事实之外,它的工作原理就像一种享受。 它有什么问题? 谢谢
尝试这个:
<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>
来自维也纳的问候
我知道到处都有答案,但我认为这是最完整的答案。
HTML
<p>Is this internet explorer?<p>
<p id="ie"></p>
现在 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;
}
您需要使用条件注释。
但是请记住,IE10+ 不尊重这些条件注释,并且会像 Firefox 和 Chrome 一样对待它们。
<!--[if IE]>
<script type="text/javascript">
window.location = "error.html";
</script>
<![endif]-->
尝试这个:
if (window.navigator.userAgent.indexOf("MSIE ") > 0)
window.location="error.html";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.