1

此页面(临时位置)上,我试图检测浏览器是否支持 Float64Array,如果不支持则重定向到此页面,这会告诉用户使用不同的浏览器。但是,重定向似乎不适用于 Windows XP 32 位上的 MSIE 8,因为错误首先发生在 libfreecell-solver.min.js 中,然后才加载。

我该如何解决?

4

1 回答 1

2

IE 浏览器有自己的内置浏览器检测方案,没有其他人采用。我认为,您可以将其用于任何低于 10 的 IE 版本。它看起来像这样:

<!--[if gte IE 8]>
<p>You're using a recent version of Internet Explorer.</p>
<![endif]-->

<!--[if lt IE 7]>
<p>Hm. You should upgrade your copy of Internet Explorer.</p>
<![endif]-->

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

您基本上会添加一个<!--[if lte IE 9]-->带有<script>标签的标签,以window.location调用您想要发送垃圾浏览器的任何地方。可能没有你想要的那么优雅,但至少它是可靠的。

取自此页面: http: //msdn.microsoft.com/en-us/library/ms537509 (v=vs.85).aspx

更新: 查看您的实际脚本,我立即看到解析/语法错误。

(function() {
    try {
        var a = new Float64Array(1);
        return; //no need
    } catch(e) {
        window.location.replace("../../js-fc-solve/incompatible-browser.html");
    } // Closing the catch block, but not closing the function block
)();

添加大括号:

(function() {
    try {
        var a = new Float64Array(1);
        return; //no need
    } catch(e) {
        window.location.replace("../../js-fc-solve/incompatible-browser.html");
    } // Closing the catch block
})(); // Close the function block before trying to call the anonymous function

这可能会或可能不会导致用户在尝试包含其他错误的库之前被重定向。此外,它可能会或可能不会检测到运行库所需检测的所有功能。我会说这取决于浏览器(没有讽刺意味)。

如果这不起作用,您可以创建一个中间页面来决定是将用户发送到求解器页面还是显示不兼容的浏览器消息。

于 2013-01-21T19:10:20.627 回答