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

标签 javascript redirect user-agent

我发现我的 javascript 密集型网站在 IE9 中无法可靠地(或根本无法)运行。

它工作,(通常,但不总是)在标题中使用兼容模式元标记,但我只想构建一个我知道在 IE9 中运行良好的页面,然后在 IE9 时将通常的页面重定向到它被检测到。通常的页面在 IE 7 和 8(以及我试过的所有其他浏览器)中都很好。

任何人都可以给我一些可以做到这一点的 javascript 吗?谢谢!

这是我常用的页面:

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

最佳答案

最简单的方法是使用 IE Conditionals .

注意:IE10 及更高版本有 removed support对于这个功能。对于现代浏览器,广泛接受的出于兼容性目的有条件地显示内容的方式是使用 feature detection。 . 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]-->

关于Internet Explorer 浏览器版本用户代理的 Javascript 重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7407182/

相关文章:

javascript - 获取二进制数据并将其保存为 .mp3 文件 Javascript

javascript - 使用 React 定期运行 fetch

apache - Struts 2.3 - 重定向 vs redirectAction

grails - 如何从Grails应用程序中的gsp重定向到 Controller 的 Action

javascript - 将一个页面重定向到另一个页面 10 秒,然后再次重定向回原始 URL

ios - 强制用户仅在 ios safari 中打开我的网站

.net - 如何使用.net更改selenium中的用户代理

javascript - 检查(从书签)是否加载了页面?

javascript - 如何使网页内容对人类私有(private)但对搜索引擎公开?

javascript - 使用 React 时如何正确地将事件监听器添加到输入