Javascript redirect for Internet Explorer browser version user agent?

不打扰是莪最后的温柔 提交于 2019-11-29 11:40:56

The simplest way would be to use IE Conditionals.

Note: IE10 and beyond have removed support for this feature. For modern browsers the widely accepted way of conditionally displaying content for compatibility purposes is using feature detection. Modernizr is a popular library built for handling feature detection.

For example:

<!--[if IE 9]>
<script type="text/javascript">
    window.location = "http://www.ie9version.com";
</script>
<![endif]-->

Examples from the conditional site:

<!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
<![if !IE]><p>You are not using Internet Explorer.</p><![endif]>

<!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
<!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->

<!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
<!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
<!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->

<!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
<![if false]>You are using a <em>downlevel</em> browser.<![endif]>

<!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->
<script LANGUAGE="JavaScript"> 
<!-- 

  if( navigator.appName.toLowerCase().indexOf("microsoft") > -1 || 
      navigator.userAgent.toLowerCase().indexOf("msie") > -1 ) { 
    window.open("http://www.pobox.com/~qed/windoze.html", "Windoze",
"dependent=no,titlebar=no,scrollbars=yes" ); 
  } 

// Paul Hsieh 
// qed at pobox dot com 
// --> 
</script>

Source: http://www.cexx.org/snicker/nomsie.htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!