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:
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 >
|
Output:
-
Before reaching the bottom:
-
After reaching the bottom:
Last Updated :
24 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...