Internet Explorer浏览器版本用户代理的Javascript重定向

Javascript redirect for Internet Explorer browser version user agent?

本文关键字:Javascript 重定向 用户代理 版本 Explorer 浏览器 Internet      更新时间:2023-09-26

我发现我的javascript密集型网站在IE9中不可靠(或根本不可靠)。

它的工作,(通常,但并不总是)与标题中的兼容模式元标签,但我只是想建立一个页面,我知道将在IE9中工作良好,然后有通常的页面重定向到它当IE9被检测到。通常的页面在ie7和ie8(以及我尝试过的所有其他浏览器)中都很好。

谁能给我一些javascript,将做到这一点?谢谢你!

这是我平常的页面:

http://ianmartinphotography.com/test-site/test/

最简单的方法是使用IE条件语句。

注意: IE10及以上版本已删除对此功能的支持。对于现代浏览器,为了兼容性目的而有条件地显示内容的广泛接受的方式是使用特性检测。Modernizr是一个用于处理特征检测的流行库。

例如:

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

条件站点示例:

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

来源:http://www.cexx.org/snicker/nomsie.htm