Detect Ipad with javascript

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 :slight_smile:

@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 :slight_smile:

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 …