How to detect whether a device is iOS without using Regular Expression in JavaScript?
The task is to detect whether the device is iOS or not without using RegExp with the help of JavaScript. There are two approaches that are discussed below.
Approach 1: Use navigator.platform property to check for the particular keywords which belongs to iOS devices using indexOf() method.
- Example:
<!DOCTYPE html><html><head><title>Detect whether a device is iOSwithout using RegExp</title></head><bodystyle="text-align: center;"><h1style="color: green;">GeeksforGeeks</h1><p>Click on the button to detectwhether a device is iOS or not?</p><buttononclick="gfg_Run()">Click Here</button><pid="gfg"></p><script>var el_down = document.getElementById("gfg");function gfg_Run() {const isIOS = ["iPad Simulator","iPhone Simulator","iPod Simulator","iPad", "iPhone","iPod"].indexOf(navigator.platform) !== -1;el_down.innerHTML = isIOS;}</script></body></html>chevron_rightfilter_none - Output:

Approach 2: Use navigator.platform property to check for the particular keywords from the list Which belongs to iOS devices. Use pop() method to take out one by one and compare them.
- Example:
<!DOCTYPE html><html><head><title>Detect whether a device isiOS without using RegExp</title></head><bodystyle="text-align: center;"><h1style="color: green;">GeeksforGeeks</h1><p>Click on the button to detectwhether a device is iOS or not?</p><buttononclick="gfg_Run()">Click Here</button><pid="gfg"></p><script>var el_down = document.getElementById("gfg");function iOS() {var Devices = ["iPad Simulator","iPhone Simulator","iPod Simulator","iPad", "iPhone","iPod"];if (!!navigator.platform) {while (Devices.length) {if (navigator.platform === Devices.pop()) {return true;}}}return false;}function gfg_Run() {el_down.innerHTML = iOS();}</script></body></html>chevron_rightfilter_none - Output:



