javascript – 浏览器嗅探
作者:互联网
我知道browsersniffing不是为多个浏览器设计网站的正确方法.然而,我的问题与设计一个对每个浏览器表现良好的网站无关.
我想让用户能够将网站安装为webapp,如果浏览器是谷歌浏览器或Firefox 4,如果它是Opera的小部件,作为扩展,如果它是Safari …等等
基本上我想用一个提供这种安装的按钮滑入div.如果浏览器是例如Safari,则无法显示webapp解决方案,因为Safari不支持它.
那么我该如何以一种好的方式做到这一点呢?
我发现这是基于功能而不是使用
Safe feature-based way for detecting Google Chrome with 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
}
它似乎适合我的需要,而且很短,不笨重,或多或少是恶搞
解决方法:
看看jQuery.browser:http://api.jquery.com/jQuery.browser/
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.Available flags are:
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.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.
标签:javascript,browser,browser-detection 来源: https://codeday.me/bug/20190626/1295857.html