浏览器嗅探 [英] Browser sniffing

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

问题描述

我知道browsersniffing是不是设计一个网站多个​​浏览器的正确方法。我的问题是但不涉及其设计为每个浏览器表现良好的网站。

I know browsersniffing is not the correct way to design a site for multiple browsers. My question however is not related to designing a site which behaves well for each browser.

我想提供用户安装的网站作为一个Web应用程序的能力,如果浏览器是谷歌Chrome或Firefox 4+,仿佛这是歌剧院,仿佛这是Safari浏览器的扩展一个小部件...等等

I want to offer the user the ability to install the site as a webapp if the browser is Google Chrome or Firefox 4+, as a widget if it's Opera, as an extension if it's Safari... and so on

基本上我想在一个div一个按钮,提供这种安装的滑动。有显示Web应用程序的解决方案没有用,如果浏览器是Safari的例子如Safari有它不支持。

Basically I want to slide in a div with a button offering this kind of install. There is no use showing the webapp solution if the browser is for example Safari as Safari has no support for it.

那么,如何做到这一点的一个好办法?

So how do I do this in a good way?

我发现这个基于特征的,而不是用户代理

I found this based on features rather than useragent

<一个href=\"http://stackoverflow.com/questions/81099/safe-feature-based-way-for-detecting-google-chrome-with-javascript\">Safe检测谷歌浏览器的JavaScript基于特征的方法是什么?

var is = {
  ff: window.globalStorage,
  ie: document.all && !window.opera,
  ie6: !window.XMLHttpRequest,
  ie7: document.all && window.XMLHttpRequest && !XDomainRequest && !window.opera,
  ie8: document.documentMode==8,
  opera: Boolean(window.opera),
  chrome: Boolean(window.chrome),
  safari: window.getComputedStyle && !window.globalStorage && !window.opera
}

这似乎为我的工作需要和很短,而不是笨重,或多或少恶搞安全

It seems to work for my needs and is short and not bulky and more or less spoof safe

推荐答案

看看jQuery.browser:的 http://api.jquery.com/jQuery.browser/

Take a look at jQuery.browser: http://api.jquery.com/jQuery.browser/

在$ .browser属性提供
  关于网络浏览器的信息
  正在访问的页面,如通过报告
  浏览器本身。它包含标志
  对于四个最prevalent的
  浏览器类(Internet Explorer中,
  Mozilla中,Webkit内核和Opera)以及
  版本信息。

The $.browser property provides information about the web browser that is accessing the page, as reported by the browser itself. It contains flags for each of the four most prevalent browser classes (Internet Explorer, Mozilla, Webkit, and Opera) as well as version information.

可用的标志是:

WebKit的(在jQuery 1.4)野生动物园
  (德precated)歌剧MSIE Mozilla时,这一
  属性是立即可用。它
  因此,安全用它来
  确定是否调用
  $(文件)。就绪()。在$ .browser
  属性是在jQuery的1.3 pcated德$ P $,
  其功能可以移动到
  在未来的一个团队支持的插件
  发布的jQuery。

webkit (as of jQuery 1.4) safari (deprecated) opera msie mozilla This property is available immediately. It is therefore safe to use it to determine whether or not to call $(document).ready(). The $.browser property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery.

由于$ .browser用途
  navigator.userAgent的确定
  平台,很容易受到欺骗
  由用户或misre presentation由
  浏览器本身。它始终是最好的
  为了避免浏览器特有的code
  完全在可能的情况。该$。支持
  属性可以用来检测
  对特定功能的支持,而
  不是依赖于$ .browser。

Because $.browser uses navigator.userAgent to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. The $.support property is available for detection of support for particular features rather than relying on $.browser.

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

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