Device. js detects mobile devices for webpage redirection

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.