How to get the Android version of your device using JavaScript? Last Updated : 05 Aug, 2024 Comments Improve Suggest changes Like Article Like Report The task is to detect the Android version of the user with the help of JavaScript. Two approaches are discussed here, the first example uses the RegExp and the second uses indexOf method to search the keyword 'android'. Note: Both codes will only work when you run them on Android devices. Approach 1: In this approach, we will use navigator.useragent property, which returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser. Then we need to search the keyword 'android' in the string returned and get the value in the temp array(which contains the version) to do that we will use a RegExp. If the temp is not null then the value at index 0 is the answer else undefined.Example: This example implements the above approach. html <!DOCTYPE html> <html lang="en"> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <style> body { text-align: center; } h1 { color: green; } .gfg { font-size: 20px; font-weight: bold; } #geeks { font-size: 24px; font-weight: bold; color: green; } </style> </head> <body> <h1> GeeksForGeeks </h1> <p class="gfg"> Click on the button to get the android version of the user. </p> <button onclick="GFG_Fun()"> click here </button> <p id="geeks"> </p> <script> let element = document.getElementById("body"); function androidV(ua) { ua = (ua || navigator.userAgent).toLowerCase(); let match = ua.match(/android\s([0-9\.]*)/i); return match ? match[1] : undefined; }; function GFG_Fun() { $('#geeks').html(androidV()); } </script> </body> </html> Output: Approach 2 In this approach, we will use navigator.useragent property, which returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser. Then we need to search if the 'android' keyword is present in the string or not to do that we will use indexOf. If it is present then get the version that is just after the keyword 'android' by using .slice() and indexOf.Example: This example implements the above approach. html <!DOCTYPE html> <html lang="en"> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <style> body { text-align: center; } h1 { color: green; } .gfg { font-size: 20px; font-weight: bold; } #geeks { font-size: 24px; font-weight: bold; color: green; } </style> </head> <body> <h1> GeeksForGeeks </h1> <p class="gfg"> Click on the button to get the android version of the user. </p> <button onclick="GFG_Fun()"> click here </button> <p id="geeks"> </p> <script> let element = document.getElementById("body"); function GFG_Fun() { let androidV = null; let ua = navigator.userAgent; if (ua.indexOf("Android") >= 0) { androidV = parseFloat(ua.slice(ua.indexOf("Android") + 8)); } $('#geeks').html(androidV); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get the Android version of your device using JavaScript? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Detect the Device is an Android Device using JavaScript? Detecting an Android device using JavaScript helps improve web experiences. By checking the user agent string, developers can identify Android devices and apply specific features or styles. This method ensures compatibility and optimizes functionality for different platformsApproachUse the navigator 2 min read How to get the width of device screen in JavaScript ? Given an HTML document that is running on a device and the task is to find the width of the working screen device using JavaScript. Example 1: This example uses window.innerWidth to get the width of the device screen. The innerWidth property is used to return the width of the device. HTML<!DOCTYP 2 min read How to get the diagonal length of the device screen using JavaScript ? Knowing the width and height of a browser window helps a web developer to enhancing the user experience. It can help in improving browser animations and the relative positioning of divisions and containers. Javascript provides a window object that represent an open browser window. It provides the va 3 min read How to detect touch screen device using JavaScript? Sometimes you might be looking for some features to include into your web-app that should only be available to devices with a touch screen. You may need this detection while introducing newer smarter controls for touch screen users in the game app or a GPS and navigation application. While there are 3 min read How to get Camera Resolution using JavaScript ? In this article, we will learn to find the maximum resolution supported by the camera. We need to request camera access from the user and once access is given we can check the resolution of the video stream and find out the resolution given by the camera. The .getUserMedia() method asks the user for 2 min read How to Enable JavaScript on Android ? JavaScript is the world's most popular lightweight, interpreted compiled programming language. It is also known as a scripting language for web pages. It is well-known for the development of web pages, many non-browser environments also use it. Therefore nowadays it is essential for users to have Ja 2 min read How to detect virtual keyboard using JavaScript ? This article, we are given an HTML document, the task is to detect a virtual keyboard if it pops up on the device's screen. A virtual keyboard is a tool that helps in the input of characters without the use of a physical keyboard. It is widely used in touchscreen devices.Approach: Unfortunately, the 2 min read Detect a device is iOS or not using JavaScript In order to detect a device whether it is iOS or not. We're going to Navigator platform and Navigator userAgent property. Navigator userAgent property This property returns the value of the user-agent header which is sent by the browser to the server. Returned value, have information about the name, 2 min read How to get the height of device screen in JavaScript ? Given an HTML document which is running on a device. The task is to find the height of the working screen device using JavaScript. Prerequisite - How to get the width of device screen in JavaScript ? Example 1: This example uses window.innerHeight property to get the height of the device screen. The 2 min read How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ? The browser on which the current page is opening can be checked using JavaScript. The userAgent property of the navigator object is used to return the user-agent header string sent by the browser. This user-agent string contains information about the browser by including certain keywords that may be 4 min read Like