web developing
16 Jul
As I wrote in my recent post I simply use the PPK BrowserDetect object to find out the browser/OS of the client. Actually I’m pretty sure there’s a similar jQuery plugin based again on that code from Quirksmode.org, but however I decided to write a simple plugin for jQuery wrapping it into a closure and exporting it in the “$” object.
You can see full working example here.
You must add a link to jquery.client.js after the jquery.js file in your code:
<html> <body> <div id="os"></div> <div id="browser"></div> <script src="./jquery-1.3.2.js"></script> <script src="./jquery.client.js"></script> <script> $('#os').html("<b>" + $.client.os + "</b>"); $('#browser').html("<b>" + $.client.browser + "</b>"); </script> </body> </html>
Now there’s a $.client object containing two strings with OS and browser, they can be referenced with:
$.client.browser $.client.os
You can append this code after you jquery.js installation. And if you’re on Firefox you simply can test with the console object:
You can download the sample code from here.
Related posts:
14 Responses for "jQuery browser and OS detection plugin"
This is very interesting. I think Jquery supported this functionality (jQuery.browser and jQuery.browser.version) but fro some reason it was deprecated in jQuery 1.3.
Since most of the time when i need this functionality is to determine the IE version (IE6 and IE7 are very different), does you plug-in also support version number?
Amir
Not the plugin does not support any version numbers. Actually $.browser.version is supporting such numbers. The $.client plugin is helping you mostly for OS detection, I guess.
Greetings,
stoimen
You can easily include the browser version functionality by adding this line in the “jquery.client.js” file (probably located at the last of the script file).
replace this line
window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser};
with this
window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser, browserversion : BrowserDetect.version };
and you will also get the browserversion.
Yeah, thanks I’ll add this soon!
Thank you guys this is exactly what i need.
Hi,
Thank you for this plugin. I have written a little introduction on my blog for your plugin.
Hi Mengu,
I’m glad I could help you! Thank you for your post, I think it’s great and I’ll definitely start following your blog.
greetings,
stoimen
Hi Stoimen,
Thank you for your comment. I’m glad at least someone liked it.
Hello, I would like to use your code in a wordpress plugin. Under what license is your code available? Just to be proper… Also when finished, I will include your links and licenses in the sources and the readme. Keep up the coding and sharing! ;]
Hi,
you’re free to use the code with no limitations, it’s completely open/free source. I’d love to see a reference in your plugin’s readme file it would be very nice.
cool dude
very nice i appreciate!
Hi,
Would be nice if you add support for iPad and other mobile devices as well.
Regards,
Kumar Amit Ranjan
Yeah! Regarding of how new is the iPad I’ve to update a bit the source code!
Thanks
Leave a reply