How to Detect a Mobile Device in jQueryIf we want to search for a particular user, a list of JavaScript syntaxes is given below that can be used to identify different mobile devices such as iPod, iPad, Android, Blackberry, Windows Phone and WebOS etc. SyntaxA Basic exampleHere, we have the most basic code to detect the mobile phone using jQuery. Supportive BrowsersThe syntaxes mentioned above and code support the following browsers:
Now, we are going to define the different syntactical logics for detecting various types of mobile phone. For Detecting iPhoneYou can search the iPhone with the help of following JavaScript code. For Detecting iPodA JavaScript code is given below to detect the iPod. For Detecting iPadHere, we have an illustration for detecting the iPad. For Detecting Android PhoneYou can detect the Android Phone with the help of following JavaScript code. For Detecting the Blackberry PhoneYou can detect the Blackberry Phone with the help of following JavaScript code. For Detecting the iDevicesYou can search for the iDevices with the help of following JavaScript code. For Detecting the Windows PhoneYou can search for the Windows phone with the help of below-given JavaScript code. For Detecting the WebOsYou can detect the WebOs with the help of below-mentioned JavaScript code. Here, we also have another method to detect the mobile phone with the help of window.matchmedia() method. You can also use the JS window.matchMedia() method for searching a cellular device according to the CSS media query. It is the best and easiest approach to predict the mobile device. Syntax Example 1: Example code for desktop. Output You will obtained the following result after the efficient execution of the above code. Example 2: Example code for the mobile phone. Output You will get the following outcome after the successful implementation of the above code. Next Topicoffset vs position in jQuery |