Javascript 如何将Internet Explorer用户重定向到新页面?

Javascript 如何将Internet Explorer用户重定向到新页面?,javascript,html,css,internet-explorer,redirect,Javascript,Html,Css,Internet Explorer,Redirect,我尝试使用以下脚本 [if IE] <script type="text/javascript"> window.location = "error.html"; </script> [endif] [如果是IE] window.location=“error.html”; [完] 除了其他浏览器(如Chrome)也在重定向到error.html页面之外,它的工作方式就像是一种款待。怎么了?谢谢您需要使用条件注释 请记住,IE10+并不尊重这些有条件的评论,并且会像F

我尝试使用以下脚本

[if IE]
<script type="text/javascript">
window.location = "error.html";
</script>
[endif]
[如果是IE]
window.location=“error.html”;
[完]

除了其他浏览器(如Chrome)也在重定向到error.html页面之外,它的工作方式就像是一种款待。怎么了?谢谢

您需要使用条件注释

请记住,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";
<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>
试试这个:

if (window.navigator.userAgent.indexOf("MSIE ") > 0)
    window.location="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>

if(navigator.appName.indexOf(“Internet Explorer”)!=-1 | | navigator.userAgent.match(/Trident.*rv[:]*11\./)
{
//此用户使用Internet Explorer
window.location=“error.html”;
}

来自维也纳的问候

我知道到处都有答案,但我认为这是最完整的答案

HTML

工作示例:

不要。认真地如果人们想使用IE,尤其是现代IE,就让他们来吧。改用特征检测和渐进增强。这与IE 11不匹配。编辑帖子…:)现在它认为Chrome是IE11,它似乎不起作用。只是想澄清一下,error.html应该放在哪里?这与IE 11不匹配。