Detecting devices with Navigator info - mobile and iPad

For those who might be looking for a possible way of detecting devices from within a browser, here is one way of doing it but can probably be expanded.

You would normally first create these variables isNewiPad and isMobile somewhere in the code, rename them if necessary and use them to decide what code should do depending on what device it is.

        isNewiPad = (/iPad/.test( navigator.platform ) && (/Mac OS X/i.test( navigator.userAgent ))) ||
          (navigator.maxTouchPoints !== undefined && navigator.maxTouchPoints > 2 && /MacIntel/.test( navigator.platform ));

        isMobile = (isNewiPad === false) && ((/iPhone|iPad|iPod/.test( navigator.platform )) ||
          (/Android|webOS|iPhone|iPad|iPod|BlackBerry|CriOS|IEMobile|Opera Mini/i.test( navigator.userAgent )));

You can see a usage example in my repository and try testing it with my IMG2MESH viewer / converter on different devices.

I did try it on M1 iPad, M2 Mac Mini, Samsung Phone and Windows 10 based laptop so hopefully it works on other devices.

To the code above or even just by itself, you could additionally add an alert to pop up when the page is loaded to let you know what the browser might report about the device, similar to this:

alert( 'navigator.platform: ' + navigator.platform + '\n' + 'navigator.userAgent: ' + navigator.userAgent + '\n' + 'navigator.maxTouchPoints: ' + navigator.maxTouchPoints);