How to detect the OS using jquery

It is very easy to detect the OS using jquery. Below are jqury function that may help you.

$(‘#osInfo’).html(“Your OS is: <b>” + $.client.os + “</b>”);

//To detect Mac OS:

if((navigator.platform.indexOf(“Mac”) != -1)) {
// code
}

$.browser.linux();

$.browser.mac();

$.browser.win();

 

To Detect Browser and browser version:

 

/* ===== Firefox ===== */
 
// Select Firefox
if (jQuery.browser.mozilla) {
    // do sth.
}
 
// Select Firefox 1.5.x to 2.x
if (jQuery.browser.mozilla && jQuery.browser.version.substr(0, 3) == '1.8') {
    // do sth.
}
 
// Select Firefox under 3.x
if (jQuery.browser.mozilla && jQuery.browser.version < '1.9') {
    // do sth.
}
 
// Select Firefox 3.0.x and above
if (jQuery.browser.mozilla && jQuery.browser.version.substr(0, 3) == '1.9') {
    // do sth.
}
 
// Select just Firefox 2.0.x
if (jQuery.browser.mozilla && jQuery.browser.version == '1.8.1') {
    // do sth.
}
 
// Select just Firefox 3.0.x
if (jQuery.browser.mozilla && jQuery.browser.version == '1.9') {
    // do sth.
}
 
// Select just Firefox 3.5.x
if (jQuery.browser.mozilla && jQuery.browser.version == '1.9.1') {
    // do sth.
}
 
// Select just Firefox 3.6.x
if (jQuery.browser.mozilla && jQuery.browser.version == '1.9.2') {
    // do sth.
}
 
// Select just Firefox 7.x
if (jQuery.browser.mozilla && jQuery.browser.version.substr(0, 1) == '7') {
    // do sth.
}
 
 
/* ===== Internet Explorer ===== */
 
// Select Internet Explorer
if (jQuery.browser.msie) {
    // do sth.
}
 
// Select Internet Explorer above 6
if (jQuery.browser.msie && jQuery.browser.version > 6) {
    // do sth.
}
 
// Select Internet Explorer 7 and below
if (jQuery.browser.msie && jQuery.browser.version <= 7) {
    // do sth.
}
 
// Select just Internet Explorer 6
if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
    // do sth.
}
 
// Select just Internet Explorer 7
if (jQuery.browser.msie && jQuery.browser.version == '7.0') {
    // do sth.
}
 
// Select just Internet Explorer 8
if (jQuery.browser.msie && jQuery.browser.version == '8.0') {
    // do sth.
}
 
// Select just Internet Explorer 9
if (jQuery.browser.msie && jQuery.browser.version == '9.0') {
    // do sth.
}
 
 
/* ===== Safari / Chrome ===== */
 
// Select Safari / Chrome
if (jQuery.browser.safari) {
    // do sth.
}
 
// Select Safari 3
if (jQuery.browser.safari && (navigator.appVersion.indexOf('3.') != -1)) {
    // do sth.
}
 
// Select Safari 4
if (jQuery.browser.safari && (navigator.appVersion.indexOf('4.') != -1)) {
    // do sth.
}
 
// Select Chrome 1
if (jQuery.browser.safari && (navigator.appVersion.indexOf('1.') != -1)) {
    // do sth.
}
 
// Select Chrome 3
if (jQuery.browser.safari && (navigator.appVersion.indexOf('3.') != -1)) {
    // do sth.
}
// Select Chrome 13
if (jQuery.browser.safari && (navigator.appVersion.indexOf('13.') != -1)) {
    // do sth.
}
 
 
/* ===== Opera ===== */
 
// Select Opera
if (jQuery.browser.opera) {
    // do sth.
}
 
// Select Opera 9.5 and above
if (jQuery.browser.opera && jQuery.browser.version >= '9.5') {
    // do sth.
}
 
// Select just Opera 9.5
if (jQuery.browser.opera && jQuery.browser.version == '9.5') {
    // do sth.
}
 
// Select just Opera 10
// Note: Opera 10's user agent looks like Opera/9.80 [...] Version/10.00
if (jQuery.browser.opera && jQuery.browser.version == '9.8') {
    // do sth.
}
Javascript code to detect iPhone and iPod browsers
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
  //code
}
Or you can use
jQuery(document).ready(function($){
    var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    if (agentID) {
        // code here
    }
});
Share this nice post:

Leave a Reply

Your email address will not be published. Required fields are marked *