How to detect the user’s device using jQuery ?
The task is to determine the user’s device, whether it is iPad or not, using JQuery. Below are the required methods:
-
Navigator userAgent Property:
This property returns the value of the header of user-agent which is sent by the browser to the server.
Returned value, have information like name, version, and platform of the browser.Syntax:
navigator.userAgent
Return value:
It returns a string, which represents the user agent string of the current browser.
Example: This example uses the navigator.userAgent property to identify the user’s device.
<!DOCTYPE HTML> <html> <head> <title> JQuery | Detect iPad users. </title> </head> <script src= </script> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 17px; font-weight: bold;"> </p> <button> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> $('#GFG_UP').text( "Click on the button to see "+ "whether user's device is iPad or not"); $('button').on('click', function() { var is_iPad = navigator.userAgent.match(/iPad/i) != null; $('#GFG_DOWN').text(is_iPad); }); </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before reaching the bottom:
-
After reaching the bottom:
Recommended Posts:
- How to detect a mobile device in jQuery?
- How to detect the device is an Android device using JavaScript ?
- Detect a device is iOS or not using JavaScript
- How to detect touch screen device using JavaScript?
- How to detect escape key press using jQuery?
- JQuery | Detect a textbox content is changed or not
- How to detect and change the content/style of a div using jQuery ?
- How to detect value change on hidden input field in JQuery ?
- How to get the width of device screen in JavaScript ?
- How to get the height of device screen in JavaScript ?
- How to detect the change in DIV's dimension ?
- How to detect HTML 5 is supported or not in the browser ?
- How to detect flash is installed or not using JavaScript ?
- How to detect search engine bots with PHP ?
- How to detect if a function is called as constructor?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

