如何检测浏览器功能? [英] How to detect the browser capabilities?

查看:75
本文介绍了如何检测浏览器功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我做过所有的阅读,
我已经明白,使用用户代理字符串是不推荐,因为它可以被欺骗。设备可以受到阻碍等等。

From all the reading that I have done, I have understood that using user-agent string is not recommended, as it can be spoofed. Devices can be hindered, etc.

我也明白,最好的选择是做一个浏览器性能测试。

I have also understood that the best option is to do a browser capability testing.

我该怎么办他?我的意思是,有一些标准的性能测试,我可以做,像这样:目标检测

How do I do his? I mean, are there some standard capability test that I could do, something like this: object detection?

一个更值得关注的是,会不会这包括一些开销,每一个用户访问该网站的时间?我知道我可以使用一些饼干对付这个。

One more concern is that, won't this include some overhead every time a user accesses the site? I know I can counter this using some cookies.

请不要建议使用像jQuery第三方插件/框架。

Please do not suggest to use a third party plugin/framework like jQuery.

推荐答案

Modernizr的是,做功能的库检测。您可以使用该库的,然后它查询你想要的功能,或者你可以看看它是如何工作的要检测并复制特定的功能到您自己的code。

Modernizr is a library that does feature detection. You can either use the library as is and then query it for the features you want or you can look at how it works for the particular features you want to detect and copy that into your own code.

你如何对个别功能做特征检测完全取决于特定的功能。

How you do feature detection for a given feature depends entirely upon the particular feature.

实际的特征检测通常是相当快的(甚至可能快于检索在Cookie /存储任何东西)。另外,你最好是关闭每次做特征检测的情况下,用户升级他们的浏览器的新版本谁的能力的变化。

The actual feature detection is generally quite fast (probably even faster than retrieving/storing anything in a cookie). Plus you are best off doing the feature detection every time in case the user upgrades to a newer version of their browser who's capabilities change.

例如,如果你想知道是否可以使用.forEach()方法对数组对象,你可以简单地使用这样的:

For example, if you want to know whether you can use the .forEach() method on the Array object, you can simply use this:

if ( Array.prototype.forEach ) {  
    // enter code here
}

这篇关于如何检测浏览器功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆