Here we will be using $.browser property og jQuery which returns the browser information. In this demo we will test this in most used browsers such as Internet Explorer, Mozilla, Chrome, Opera, etc. I hope you will like this.
Please see this article in my blog here.
NB: Using $.browser is not recommended by jQuery itself, so this feature has been moved to the jQuery.migrate plugin which is available for downloading if the user want. It is a vulnerable practice to use the same. Use it only if needed. It is always better to not use browser specific codes.
Using the code
First thing you need to do is create a page.
- <!DOCTYPE html>
- <html>
-
- <head>
- <title>Find Browser In JQuery - Sibeesh Passion</title>
- </head>
-
- <body>
- Find Browser In JQuery - Sibeesh Passion
- </body>
-
- </html>
Then you need to include the needed script.
- <script src="http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js"></script>
- <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
As you have noticed I have included the
code. It is just because this feature is deprecated and moved to this js.
Now you need to write the following script.
- <script>
- $(document).ready(function() {
- if ($.browser.webkit) {
- alert("Hooray WebKit!" + " Version: " + $.browser.version);
- } else if ($.browser.msie) {
- alert("Hooray IE!" + " Version: " + $.browser.version);
- } else if ($.browser.mozilla) {
- alert("Hooray mozilla!" + " Version: " + $.browser.version);
- }
- $.each($.browser, function(i, val) {
- $("<div>" + i + " : <span>" + val + "</span>")
- .appendTo(document.body);
- });
- });
- </script>
We are appending the browser details to the DOM. So that it is always better to use some CSS to improve the readability.
- <style>
- div {
- width: 500px;
- border: 1px solid #ccc;
- border-radius: 5px;
- padding: 10px;
- margin: 10px;
- box-shadow: 1px 1px 1px #999;
- color: #f90;
- font-style: oblique;
- text-align: center;
- }
- </style>
Now please run your browser, you can see the following output.
Complete Code - <!DOCTYPE html>
- <html>
-
- <head>
- <title>Find Browser In JQuery - Sibeesh Passion</title>
- <script src="http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js"></script>
- <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
- <script>
- $(document).ready(function() {
- if ($.browser.webkit) {
- alert("Hooray WebKit!" + " Version: " + $.browser.version);
- } else if ($.browser.msie) {
- alert("Hooray IE!" + " Version: " + $.browser.version);
- } else if ($.browser.mozilla) {
- alert("Hooray mozilla!" + " Version: " + $.browser.version);
- }
- $.each($.browser, function(i, val) {
- $("<div>" + i + " : <span>" + val + "</span>")
- .appendTo(document.body);
- });
- });
- </script>
- <style>
- div {
- width: 500px;
- border: 1px solid #ccc;
- border-radius: 5px;
- padding: 10px;
- margin: 10px;
- box-shadow: 1px 1px 1px #999;
- color: #f90;
- font-style: oblique;
- text-align: center;
- }
- </style>
- </head>
-
- <body>
- Find Browser In JQuery - Sibeesh Passion
- </body>
-
- </html>
Conclusion
Did I miss anything that you may think which is needed? Have you ever wanted to find out the browser details on client side? Could you find this post useful? I hope you liked this article. Please share me your valuable suggestions and feedback.
Your turn. What do you think?
If you have any questions, then please mention it in the comments section.
Omid NasriPosted Sep 23, 2016, 5:10 PM
Good one
Santhakumar MunuswamyPosted Oct 18, 2015, 3:24 AM
Good one
Sibeesh VenuPosted Oct 14, 2015, 12:52 AM
Gowtham K Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:51 AM
Gopi Chand Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:51 AM
Rakesh Chavda Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:49 AM
Mukesh Kumar Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:49 AM
Jacob Robinson Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:49 AM
Debendra Dash Thanks a lot
Sibeesh VenuPosted Oct 14, 2015, 12:48 AM
Nilesh Jadav Thanks a lot
Gowtham KPosted Oct 13, 2015, 11:55 AM
Nice Share
Gopi ChandPosted Oct 13, 2015, 11:05 AM
Excellent work Sibeesh
RakeshPosted Oct 13, 2015, 10:24 AM
Good share
Mukesh KumarPosted Oct 13, 2015, 8:32 AM
Good one
Jacob RobinsonPosted Oct 13, 2015, 7:25 AM
Nice One...
Debendra DashPosted Oct 13, 2015, 6:18 AM
good one...
Nilesh JadavPosted Oct 13, 2015, 6:08 AM
Great work sir
Sibeesh VenuPosted Oct 13, 2015, 6:07 AM
Rajeesh Menoth Thank you
Sibeesh VenuPosted Oct 13, 2015, 6:07 AM
Harshad Pansuriya Thank you
Rajeesh MenothPosted Oct 13, 2015, 5:55 AM
Nice Share!
Harshad PansuriyaPosted Oct 13, 2015, 5:43 AM
Nice one