Js recognizes Android, ios, and pc terminals, as well as shields WeChat

Source: Internet
Author: User

Js identifies Android, ios, and pc terminals, as well as shielding

This function is mainly used for download,

Android is definitely different from ios,

How to jump to a device based on the user's device during access from different devices.

In addition, if the accessed address is yes, the redirection will be blocked.

You need to identify and prompt to use another browser to open this URL.

The code is simple. The complete code is as follows:

 1  2 
3 4 5 6 11 <script> 12 function detectOS () {13 var osUserAgent = navigator. userAgent. toLowerCase (); 14 if (osUserAgent. indexOf ("iphone")>-1 | osUserAgent. indexOf ("ipad")>-1 | osUserAgent. indexOf ("ipod")>-1) {15 if (osUserAgent. indexOf ("micromessenger")>-1) {16 return "wechat"; 17} 18 // alert ("Note: Only jailbreak users can install"); 19 top. location. href = 'HTTP: // www.apple.com/'000020 return "iphone"; 21} 22 if (osUserAgent. indexOf ("android")>-1 | osUserAgent. indexOf ("adr")>-1) {23 if (osUserAgent. indexOf ("micromessenger")>-1) {24 return "wechat"; 25} 26 top. location. href = 'HTTP: // www.baidu.com '; 27 return "android"; 28} 29 if (osUserAgent. indexOf ("win")>-1) {30 top. location. href = 'HTTP: // www.baidu.com '; 31 return "windows"; 32} 33 return osUserAgent; 34} 35 detectOS (); 36 </script> 383940

4142

Three if statements are used for query: ios, Android, or win (pc ),

Added

If (osUserAgent. indexOf ("micromessenger")>-1) {return "wechat";} verify whether it is enabled in. if you do not need this function, delete it.
Top. location. href = 'HTTP: // www.apple.com/'specifies the address of the corresponding device. Finally, there is an image in the body. When it is accessed, the image is displayed, and the image content is prompted to be opened in another browser.

Related Article

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.