Giter VIP home page Giter VIP logo

jquery-browser-plugin's Introduction

NPM

Build Status

A jQuery plugin for browser detection. jQuery v1.9.1 dropped support for browser detection, and this project aims to keep the detection up-to-date.

Installation

Include script after the jQuery library:

<script src="/path/to/jquery.browser.js"></script>

Alternatively, you can use the plugin without jQuery by using the global object jQBrowser instead of $.browser.

Usage

Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE 11.

$.browser.msie;

Returns true if the current useragent is some version of a WebKit browser (Safari, Chrome and Opera 15+)

$.browser.webkit;

Returns true if the current useragent is some version of Firefox

$.browser.mozilla;

Reading the browser version

$.browser.version

You can also examine arbitrary useragents

jQBrowser.uaMatch();

Things not included in the original jQuery $.browser implementation

  • Detect specifically Windows, Mac, Linux, iPad, iPhone, iPod, Android, Kindle, BlackBerry, Chrome OS, and Windows Phone useragents
	$.browser.android
	$.browser.blackberry
	$.browser.cros
	$.browser.ipad
	$.browser.iphone
	$.browser.ipod
	$.browser.kindle
	$.browser.linux
	$.browser.mac
	$.browser.msedge
	$.browser.playbook
	$.browser.silk
	$.browser.win
	$.browser["windows phone"]

Alternatively, you can detect for generic classifications such as desktop or mobile

	$.browser.desktop
	$.browser.mobile
	// User Agent for Firefox on Windows
	User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0
	
	$.browser.desktop // Returns true as a boolean
	// User Agent for Safari on iPhone
	User-Agent: Mozilla/5.0(iPhone; CPU iPhone OS 7_0_3 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B508 Safari/9537.53
	
	$.browser.mobile // Returns true as a boolean
  • Detect the browser's major version
	// User Agent for Chrome
	// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36
	
	$.browser.versionNumber // Returns 32 as a number
  • Support for new useragent on IE 11
  • Support for Microsoft Edge
  • Support for WebKit based Opera browsers
  • Added testing using PhantomJS and different browser user agents

Testing

Testing for this plugin is done with Casperjs v1.1 to take advantage of multiple phantomjs browsers with different user agents.

For instructions on how to install Casperjs v1.1 go to http://docs.casperjs.org/en/latest/installation.html

Note: Testing requires Casperjs v1.1

Install the grunt-cli dependency by running npm install -g grunt-cli Run npm install to install all dependencies including grunt and all tasks

Once Casperjs and the grunt-cli npm package is installed you can execute all the tests by using:

npm test

Development

Attributions

jquery-browser-plugin's People

Contributors

bhamodi avatar bitdeli-chef avatar gabceb avatar jamiter avatar jcbrand avatar mwiencek avatar phistuck avatar promatik avatar thomasstephane avatar thomaswelton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-browser-plugin's Issues

jquery.browser.min.js not packable

We use assetic inside of Symfony to pack multiple JavaScript files into a single one. This process doesn't alter the individual files' content, but appends each one into a single file (minimizing http downloads).

The Problem is that jquery.browser.min.js is missing a trailing semicolon, which causes JavaScript errors when jquery.browser.min.js is not the last entry in the packed js file. Just adding the ; at the end of the minified jquery.browser.min.js solves the problem and enables us to pack it together with other JS files.

Opera 12.11 has $.browser.versionNumber == 12.11 (not 12)

Hi,

$.browser.versionNumber set to 12.11 in Opera 12.11

According to the description:

Detect the browser's major version

it should be 12. Shouldn't it?

Opera's version info:

About Opera
Version information
Version 12.11 
Build 1661 
Platform Win32 
System Windows 7

I think the problem is in parseFloat(matched.version, 10) (dist/jquery.browser.js:56).
Should be something like this: parseInt( $.browser.version.split(".")[0] ). Split string and get the first array item - the major version number and convert it to int.

Make jquery dependency optional

I know this sounds a little weird because the name of this project is jquery-browser-plugin, but it doesn't seem to use jquery for anything. Currently I want to use this plugin to detect the browser before the app launches, therefor I need jquery (I use jquery version 2, old IE versions are not supported) which may break on non supported browsers.

Consistent code indentation

@gabceb The code is very inconsistently indented. The JS uses tab and space mixture, as does the tests, but the CoffeeScript uses spaces only. Most JS style guides recommend two space soft tab indentation. I noticed this while working on #24, and it made it a bit hard to edit. I don't know if you want to change it, but I thought I wanted to mention it.

Problem to detect old firefox version

I have a problem to detect version of older Firefox, for example:
Mozilla/5.0 (Windows NT 10.0; WOW64) Gecko/20100101 Firefox/40.0

I see that Mozilla made some changes:
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0

But I am sure, that it worked in older version of jquery.browser plugin

Some regressions in plugin

I'm opening this not only for reporting, but also to document what I am seeing. I will update this until I've uncovered everything.

c911970 has broken a number of tests and thus functionality:

  • Browser should be Safari on Mac
  • Browser should be Safari on iPad
  • Browser should be Safari on iPhone
  • Browser name should be Android
  • There are three more broken tests right now, but they are not directly related to this, and are out of scope for the issue at hand.

Through manual testing, I've found browser.safari is returning undefined, and browser.name is returning "version" with some UAs.

The script changes in that commit, however, were only applied to the script in the test/src folder. These issues do not reproduce with the script under dist/.

I am partly to blame here, as some of the changes made were mine (see the le717-safari-version branch and #35).

TODO

  • Make browser.safari work again
  • Research what UAs are breaking browser.name and fix that
  • Ensure #35 is still fixed
  • Code review (#49)

Support IE11 user agent

The user agent string has changed in IE 11 -- it no longer says 'msie' but "IE11" instead.

Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0)

Can you support $.browser.msie and $.browser.version come back with 11.0?

IEMobile 11 Update User Agent Changes

Microsoft announced that Internet Explorer 11 in the upcoming Windows Phone 8.1 Update will change the user agent (again) and it looks somewhat like this.

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 920) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 (Ref)

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; 909) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 (Ref)

Jesus.

The update would take months to get to the consumers, so it is kind of subject to change, hopefully, but unlikely.

Here is a reddit thread if you're interested.

Do you support Chrome OS?

In Chrome OS, I can’t find any platform value.
please check it.
userAgent is as follows

Mozilla/5.0 (X11; CrOS i686 14.811.2011)
AppleWebKit/535.1 (KHTML, like Gecko)
Chrome/14.0.834.0 Safari/535.1

$.browser.msie doesn't work

$.browser.msie 
"Unable to get value of the property 'msie': object is null or undefined" 

I get the above in IE9.

Safari version incorrectly detected

I am running Safari 7.0 on OSX 10.9, and the version number is incorrectly detected. I have been told this also happens on Safari 6.05.

The cause seems to be that the library is detecting the webkit version, rather than the Safari version. Below is my current user agent.

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71

The detected browser version here is 537.71, rather than the expected 7.0.

I have tried fixing this myself, but have only come up with a rudimentary workaround as I am not too slick with regex. I added a line to the match regex which detects Safari:

var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf('trident') >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];

Then after the matching, I have added this simple if statement to check for Safari, and do another regex to determine the version.

if (match[1] === 'safari') {
    match[2] = /(version)[ \/]([\w.]+)/.exec( ua )[2];
}

I'm sure there is a neater way to do this, but for now this does work.

Attribution

It's pretty standard for a commonly used package to have a license and attribution (source) at the top of the file. I need this, as I literally use hundreds of libraries like this, and I cannot keep track of where they all are.

It would be a lot better for us to be able to quickly identify the license and plugin source than remembering this website url.

thanks,
Kevin

webview detection

Is this possible with this plugin? I want to know if a user is on a webview (for example if he opens a page link in facebook)

Copyright violation

You can't copy/paste code from jQuery and change the copyright to yourself. You need to restore the original copyright info or remove this.

Issue Migraing from Older jQuery.browser Plugin to This

Hey,

The old Jquery Browser plugin (http://jquery.thewikies.com/browser/) support a property called browser.name which can be reference to output the name instead of using a bunch if statements - if browser.msie, if etc...

We're migrating to this plugin, and that was the key missing piece.

All I did was add this line to the if ( matched.browser) check:
browser.name = matched.browser;

If you add that in, and in to the min version, that would be great!

Latest release is missing a dot

The latest release is tagged v0.05, but the previous v0.0.4. This makes installing your plugin with bower more difficult. Could you include a second dot in the next release tag?

Thanks

Error in IE11 detection

You have an error in the following condition (detecting IE11):

ua.indexOf("trident") || ...

If "trident" substring is not found, ua.indexOf("trident") returns -1, which is casted to true.
(Also, if "trident" substring is on first position, indexOf returns 0, which is casted to false)

So, the correct condition should be:

ua.indexOf("trident") != -1 || ...

or:

ua.indexOf("trident") >= 0 || ...

version bump

seems like quite a while since git has been tagged with the latest version.
are you able to do a bump so i can remove the git repo address from my bower.json?

Windows Phone not recognized

Name: Windows Phone
Modell: NOKIA Lumia 520
Software: Windows Phone 8.1 Update
(OS Version: 8.10.14219.341)

$.browser {
"webkit":true,
"version","537",
"versionNumber":537,
"iphone":true,
"mobile":true,
"name":"webkit",
"platform":"iphone"
}

"Mozilla/5.0 (Mobile; WIndows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebkit/537 (KHTML, like Gecko) Mobile Safari/537"

Thanks (:

Commonjs Compatibility

Since you have this published to npm, it would be awesome if it was commonjs-compatible, which it currently is not. #18 mentions that umd is a good way to solve this problem, it would work for cjs as well. Trying to use this in a project that launches shortly, happy to pitch in with pull requests etc -- are you ok with this? If not I can fork, but I'd rather work with you to make it happen on the original πŸ˜€

just a little function for detection

the following builds a string of browser information, like you might want to do for analytical purposes.

requires jquery-browser-plugin and jQuery

var browser = '';
($.browser.msie == true) ? browser += ' MSIE /' : false;
($.browser.ipad == true) ? browser += ' ipad /' : false;
($.browser.webkit == true) ? browser += ' webkit /': false;
($.browser.mozilla == true) ? browser += ' mozilla /': false;
var opera = ((!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) == true) ? browser += ' opera /' : false;
((!!window.chrome && opera === false) == true) ? browser += ' chrome /' : false;
((Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) == true) ? browser += ' safari /' : false;
((/*@cc_on!@*/false || !!document.documentMode) == true) ? browser += ' IE /' : false;
((typeof InstallTrigger !== 'undefined') == true) ? browser += ' FF /' : false;
($.browser.iphone == true)  ? browser += ' iphone /' : false;
($.browser["windows phone"] == true) ? browser += ' windows phone /' : false;
($.browser.android == true)  ? browser += ' android /' : false;
($.browser.cros  == true) ? browser += ' chrome os /' : false;
($.browser.win  == true) ? browser += ' windows /' : false;
($.browser.mac  == true) ? browser += ' mac /' : false;
($.browser.linux  == true) ? browser += ' linux /' : false;
($.browser.desktop  == true) ? browser += ' desktop /' : false;
($.browser.mobile  == true) ? browser += ' mobile /' : false;
($.browser.version == true) ? browser += $.browser.version : browser +=' Unk /';
alert(browser);

Mismatched anonymous define() modules ...

The anonymous module registration is not allowed in require.js and causes the error message
"Mismatched anonymous define() modules ..."

Can easily be solved by naming the module:

  •    define(['jquery'], function ($) {
    
  •    define('jquery-browser',['jquery'], function ($) {
    

jQBrowser.mobile returns undefined instead of false

Some of the variables are not initialized to false:

EXISTING:
if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
browser.mobile = true;
}

checking for jQBrowser.mobile on a desktop browser will return 'undefined' instead of false.

FIX:
if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
browser.mobile = true;
} else {
browser.mobile = false;
}

The same problem for browser.desktop, browser.safari, browser.xyz

Check for IEMobile please

well you have nicely developed plugin , I want to test if browser is Nokia Lumia's IEMobile browser or not !!!

Browser plugin

Issue in Jquery browser plugin.

SCRIPT5007: Unable to get value of the property 'msie': object is null or undefined

Publish on npm?

Would you consider uploading this to npm? I've been looking around for a jQuery plugin like this after learning $.browser was removed and writing code last night to parse to user-agent myself. Posting to npm is a great way to have others find this wonderful script and keep it up-to-date.

Opera 15+ detection

Beginning from version 15, Opera moved from own Presto engine to WebKit/Blink, changing UserAgent as following:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.20 Safari/537.36 OPR/15.0.1147.18 

So you should probably detect OPR/... substring for newer versions of Opera.

Android Browser is recognized as Safari

Hey, i did a check on the default Android browser. You're script is giving me the following feedback:
["safari:true","version:4.0","versionNumber:4","android:true","webkit:true","name:safari","platform:android"]

On whatbrowser.org the browser is stated as "Android 4"-Browser.
Maybe you could implement the regex from the given website.

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.