Giter Club home page Giter Club logo

jquery.browser's Introduction

Browser and mobile platform sniffing scripts (plugin & standalone)

These are minimalist scripts that weigh under 300B once minified and gzipped. They're tailored to my own needs and should be customized to suit your needs (detecting desktop operating systems for instance). If you are looking for a full-featured library and are ready to send 4K of JS to your users, have a look at platform.js.

API

When loaded in the page after jQuery, results are available using:

jQuery.browser.<name>
jQuery.browser.version

jQuery.platform.<name>
jQuery.platform.version

// Example when tested in Firefox
jQuery.browser.mozilla === true;
// Example when tested on Android
jQuery.platform.android === true;

When loaded in the page without jQuery or before jQuery, results are available using:

browser.<name>
browser.version

platform.<name>
platform.version

// Example when tested in Firefox
browser.mozilla === true;
// Example when tested on Android
platform.android === true;

Tested browsers

The following browser <name>s are being searched for in the user-agent string:

mozilla
safari
chrome
msie
opera

Tested mobile platforms

The following mobile platform <name>s are being searched for in the user-agent string:

ipod
iphone
ipad
android
blackberry
windowsPhone
symbian

Precautions

Browser and other user-agent sniffing is generally a bad practice in Web development. If you need to know which features are available in a users' browser, you should use future proof feature detection techniques or libraries (see modernizr.js or jQuery.support if you use jQuery).

There are still valid use cases for browser sniffing:

  • as a fallback when features can't be detected or inferred (see The Undetectables)
  • to match the appearance of you webapp with a platform (beware, most operating systems can be skinned)
  • to offer links to specific browser extensions or mobile apps, according to the browser/platform

In any case, remember that user-agent strings can be spoofed.

License

MIT licensed http://louisremi.mit-license.org/

jquery.browser's People

Contributors

hongaar avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.