有没有办法一次性执行所有Modernizr测试?

时间:2022-07-17 09:35:16

I'm new to Modernizr and I'm just looking for a simple way to check for overall browser compatibility. I've generated a Modernizr script to test for only the most essential components of my web application, which is highly dependent on HTML5, CSS3, and modern JavaScript methods. Is there a way to run all of these tests simultaneously? Looking over the documentation, I see plenty of ways to test each feature one by one, but I'm not seeing a way to do it all at once. I'm hoping to do something like this:

我是Modernizr的新手,我只是想找一种简单的方法来检查浏览器的整体兼容性。我已经生成了一个Modernizr脚本来测试我的Web应用程序中最重要的组件,它高度依赖于HTML5,CSS3和现代JavaScript方法。有没有办法同时运行所有这些测试?查看文档,我看到有很多方法可以逐个测试每个功能,但我没有看到一次完成所有功能的方法。我希望做这样的事情:

Pseudocode

伪代码

if (Modernizr.testAll()) {
  // Load site
} else {
  // Redirect to compatibility page
}

2 个解决方案

#1


4  

It turns out that all the tests are stored as booleans directly in the Modernizr object, so if you're building an application with a lot of feature dependencies and you want to test them all at once, use this:

事实证明,所有测试都直接存储在Modernizr对象中作为布尔值,因此如果您构建的应用程序具有许多功能依赖性并且您想要一次性测试它们,请使用以下命令:

var supported = true;
for (var feature in Modernizr) {
  if (typeof Modernizr[feature] === "boolean" && Modernizr[feature] == false) {
    supported = false;
    break;
  }
}

#2


0  

I was looking for the same thing and I came up with the following code:

我正在寻找相同的东西,我想出了以下代码:

for (var feature in Modernizr) 
{
    if (typeof Modernizr[feature] === "boolean")
    {
        console.log("Modernizr_" + feature + ": " +Modernizr[feature]);

        for (var subFeature in Modernizr[feature])
        {
            if (typeof Modernizr[feature][subFeature] === "boolean")
            {
                console.log("Modernizr_" + feature + "_"+ subFeature + ": " + Modernizr[feature]);          
            }
        }
    }


}

HTH!

HTH!

#1


4  

It turns out that all the tests are stored as booleans directly in the Modernizr object, so if you're building an application with a lot of feature dependencies and you want to test them all at once, use this:

事实证明,所有测试都直接存储在Modernizr对象中作为布尔值,因此如果您构建的应用程序具有许多功能依赖性并且您想要一次性测试它们,请使用以下命令:

var supported = true;
for (var feature in Modernizr) {
  if (typeof Modernizr[feature] === "boolean" && Modernizr[feature] == false) {
    supported = false;
    break;
  }
}

#2


0  

I was looking for the same thing and I came up with the following code:

我正在寻找相同的东西,我想出了以下代码:

for (var feature in Modernizr) 
{
    if (typeof Modernizr[feature] === "boolean")
    {
        console.log("Modernizr_" + feature + ": " +Modernizr[feature]);

        for (var subFeature in Modernizr[feature])
        {
            if (typeof Modernizr[feature][subFeature] === "boolean")
            {
                console.log("Modernizr_" + feature + "_"+ subFeature + ": " + Modernizr[feature]);          
            }
        }
    }


}

HTH!

HTH!