Device. js is a js library used to detect devices. It is small but easy to use. When we finish the webpage of the mobile phone version, we usually need to jump to it, because most users remember the only domain name of our website, rather than the second-level domain name and second-level directory, it will increase user costs. Therefore, it is very important to achieve dynamic jump.
Step 1: Use device. js to detect mobile devices:
Introduce the device. js file
<Script src = "device. min. js"> </script>
Step 2: Use device. js to detect mobile devices:
Determine
<Script type = "text/javascript">
If (device. mobile ()){
Window. location = "shouji.html"; // you can change it to an http address.
}
</Script>
There are many methods for device. Below are some commonly used methods:
Device. mobile () & rarr; detects whether the device is a mobile phone;
Device. ipad () & rarr; detect whether the device is an ipad;
Device. portrait () & rarr; check whether the device is vertical;
Device. landscape () & rarr; checks whether the device is horizontal;
Device. iphone () & rarr; detects whether the device is an Apple phone;
Device. android () & rarr; detects whether the device is an android phone;
Device. tablet () & rarr; check whether the device is a large screen mobile phone (more than 7 inch );
Supplement
Generated CSS Class:
Device |
CSS Classes |
IPad |
Ios ipad tablet |
IPhone |
Ios iphone mobile |
IPod |
Ios ipod mobile |
Android Phone |
Android mobile |
Android Tablet |
Android tablet |
BlackBerry Phone |
Blackberry mobile |
BlackBerry Tablet |
Blackberry tablet |
Windows Phone |
Windows mobile |
Windows Tablet |
Windows tablet |
Firefox OS Phone |
Fxos mobile |
Firefox OS Tablet |
Fxos tablet |
Desktop |
Desktop |
Orientation |
CSS Classes |
Landscape |
Landscape |
Portrait |
Portrait |
Related Javascript functions
Device |
JavaScript Method |
Mobile |
Device. mobile () |
Tablet |
Device. tablet () |
IOS |
Device. ios () |
IPad |
Device. ipad () |
IPhone |
Device. iphone () |
IPod |
Device. ipod () |
Android |
Device. android () |
Android Phone |
Device. androidPhone () |
Android Tablet |
Device. androidTablet () |
BlackBerry |
Device. blackberry () |
BlackBerry Phone |
Device. blackberryPhone () |
BlackBerry Tablet |
Device. blackberryTablet () |
Windows |
Device. windows () |
Windows Phone |
Device. windowsPhone () |
Windows Tablet |
Device. windowsTablet () |
Firefox OS |
Device. fxos () |
Firefox OS Phone |
Device. fxosPhone () |
Firefox OS Tablet |
Device. fxosTablet () |
Orientation |
JavaScript Method |
Landscape |
Device. landscape () |
Portrait |
Device. portrait () |