Detect Your Client With Jquery Script

Hello everyone, welcome to the tutorial on jQuery. Today I am going to share a very simple but effective scripts for how to detect client using jQuery. As a programmer sometimes we need to detect client OS and their browser information. So, if we can get client information then we can easily execute specific function dedicate for that client.

Like if client comes from a desktop web browser then we can show full website , on the other hand when client comes from a mobile device then we can redirect them to a mobile compatible website. It’s very efficient and user friendly also.

I’ve hosted full scripts in my server for your download. You will find them in below of the tutorial. Demo also available for you. You can detect any kind of client like mozilla firefox, IE, safari, opera, chrome . In bonus , this code can also detect operating system that your client used.

– jQuery Scripts:

if( $.client.os == "Windows"){
    $('#os').html("Your browser is running on: " + $.client.os + "");
    }
    else{
        $('#os').html("Your browser is running on: " + $.client.os + "");
    }

if( $.client.browser =="Firefox"){
    $('#browser').html("Your browser is: " + $.client.browser + "");
}
else if( $.client.browser =="Chrome"){
    $('#browser').html("Your browser is: " + $.client.browser + "");
}
else if( $.client.browser =="Explorer"){
    $('#browser').html("Your browser is: " + $.client.browser + "");
}
else{
    $('#browser').html("Your browser is: " + $.client.browser + "");
}

– HTML Scripts:

<div id="os"></div>
<div id="browser"></div>

When you run this code you will see texts like below. Have a look –

Your browser is running on: Windows
Your browser is: Firefox

Download latest Jquery code library from:

http://code.jquery.com/jquery-1.7.2.min.js

Demo Available:

http://demos.coolajax.net/detectclient

Download Full code from:

http://demos.coolajax.net/detectclient/code.zip

I think this code will help a lot in your next project. Thanks a lot for reading my tutorial.

Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!

Share It

Related Posts