栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Modernizr来检测IE的正确方法?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Modernizr来检测IE的正确方法?

我同意我们应该测试功能,但是很难找到一个简单的答案:“现代浏览器支持哪些功能,而旧浏览器不支持?”

因此,我启动了许多浏览器,并直接检查了Modernizer。我添加了一些我绝对需要的功能,然后添加了“
inputtypes.color”,因为它似乎涵盖了我关心的所有主要浏览器:Chrome,Firefox,Opera,Edge
…和IE11。现在,我可以轻轻建议用户使用Chrome / Opera / Firefox / Edge会更好。

这就是我使用的-您可以编辑事物列表以测试您的特定情况。如果缺少任何功能,则返回false。

public CheckBrowser(): boolean{    let tests = ["csstransforms3d", "canvas", "flexbox", "webgl", "inputtypes.color"];    // Lets see what each browser can do and compare...    //console.log("Modernizr", Modernizr);    for (let i = 0; i < tests.length; i++)    {        // if you don't test for nested properties then you can just use        // "if (!Modernizr[tests[i]])" instead        if (!ObjectUtils.GetProperty(Modernizr, tests[i]))        { console.error("Browser Capability missing: " + tests[i]); return false;        }    }    return true;}

这是“ inputtypes.color”所需的GetProperty方法。

public static GetProperty(target: any, propertyName: string): any{    if (!(target && propertyName))    {        return undefined;    }    var o = target;    propertyName = propertyName.replace(/[(w+)]/g, ".$1");    propertyName = propertyName.replace(/^./, "");    var a = propertyName.split(".");    while (a.length)    {        var n = a.shift();        if (n in o)        { o = o[n]; if (o == null) {     return undefined; }        }        else        { return undefined;        }    }    return o;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/615047.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号