How to detect if the device is iPad with javascript in the latest version the userAgent looks like this…
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15
???
How to detect if the device is iPad with javascript in the latest version the userAgent looks like this…
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15
???
I would suggest to use CSS for the themes/templates instead of using the jQuery but here it is
Thank you but I need to know if the device is ipad…
Can I ask why do you need to target iPad devices?
if(iOS()){
alert('iOS');
}
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
||
(navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
I am working on a Javascript project and I there is a bug specific only on Ipad and I have to write special code for it…
You function is detecting IOS, I need just Ipad, I tried everything
@FWDesign - what happens if people have disabled Javascript?
These links may help:
If you go on Google Search and type in “detect if device is ipad using javascript” then there are pages of possible answers to your question.
This is a Javascript project
I tried the thing is that in the latest version IOS is showing a stupid thing when using userAgent, give it a try if you don’t believe me!
It’s because depending on the iPad, some of the ‘iPad’ may be registered as iOS instead. You need to check with the iPad that you’re having problem first - to make sure how the “userAgent” is registered, then you can target but…
If it doesn’t work on iPad, most likely it’s Safari issue, you should target Safari instead ( or ask the user to get the iPad updated, it’s probably not even iPad issue, it’s something else )
I don’t think is possible with the latest version since the userAgent is returning crap, as always Apple is doing the job right!
Install a Firefox or Opera on iPad and try again. Most likely, it’s browser issue and you won’t have the problem with the new browser.
Then you can change your strategy
I will try …
This is probably long since past being useful to you, but you might’ve gotten this userAgent result if you were testing this with XCode Simulator. Apparently the userAgent string being returned is for your Mac that you’re previewing Simulator on, not the Simulator itself.
Logging window.navigator.userAgent with Simulator results in:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15
Logging the same call on an actual iPad gets me this:
Mozilla/5.0 (iPad; CPU OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1