How to change the user agent of iPad OS and how to determine the device by JavaScript

Since the user agent has changed for the iPad OS, it may not be recognized as an iPad by the previous JavaScript-based device determination. This is because the iPad OS now uses the same user agent as the desktop version of Safari.

To solve this, use the following JavaScript code

var agent = window.navigator.userAgent.toLowerCase(); 
var ipad = agent.indexOf('ipad') > -1 || agent.indexOf('macintosh') > -1 && 'ontouchend' in document; 
if(ipad == true){ 
 alert("The device you are looking at is an iPad.") ; 
}else{ 
 alert("The device you are looking at is not an iPad.") ; 
 }

This code checks if the user agent contains ‘ipad’ or ‘macintosh’ and also if the ‘ontouchend’ event is present in the document object. This allows for accurate device determination even on the iPad OS.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top