【问题标题】:How to redirect Internet Explorer users to a new page?如何将 Internet Explorer 用户重定向到新页面?
【发布时间】:2014-12-02 00:04:06
【问题描述】:

我尝试过使用以下脚本

[if IE]
<script type="text/javascript">
window.location = "error.html";
</script>
[endif]

除了 Chrome 等其他浏览器也重定向到 error.html 页面这一事实之外,它就像一种享受。它有什么问题?谢谢

【问题讨论】:

标签: javascript html css internet-explorer redirect


【解决方案1】:

试试这个:

<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>

来自维也纳的问候

【讨论】:

【解决方案2】:

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

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;
}

工作示例: https://codepen.io/gerritman123/pen/VjrONQ

【讨论】:

    【解决方案3】:

    您需要使用条件 cmets。

    但请记住,IE10+ 不尊重这些条件 cmets,并将像 Firefox 和 Chrome 一样对待它们。

    <!--[if IE]>
    <script type="text/javascript">
    window.location = "error.html";
    </script>
    <![endif]-->
    

    【讨论】:

      【解决方案4】:

      试试这个:

      if (window.navigator.userAgent.indexOf("MSIE ") > 0)
          window.location="error.html";
      

      【讨论】:

      猜你喜欢
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 2016-11-05
      • 1970-01-01
      • 2020-11-11
      • 2011-09-24
      • 1970-01-01
      相关资源
      最近更新 更多