Mobile version and PC version recognition

Source: Internet
Author: User
Tags perl script

1. By user-agent

       //Judging whether it comes from a mobile phone terminal         Public BOOLcheckmoble () {if(Isusercheckmobile = =false)                return false; stringuseragent = request.headers["user-agent"]; if(Useragent.indexof ("Noki") >-1||//Nokia phones and emulatorsUseragent.indexof ("Android") >-1||//Android PhoneUseragent.indexof ("IPhone") >-1||//IPhone PhoneUseragent.indexof ("Eric") >-1||//Ericsson WAP phones and emulatorsUseragent.indexof ("WapI") >-1||//Ericsson wapide 2.0Useragent.indexof ("MC21") >-1||//Ericsson MC218Useragent.indexof ("AUR") >-1||//Ericsson R320Useragent.indexof ("R380") >-1||//Ericsson R380Useragent.indexof ("Up . B") >-1||//Up . BrowserUseragent.indexof ("WINW") >-1||//Winwap BrowserUseragent.indexof ("UPG1") >-1||//Up . SDK 4.0Useragent.indexof ("upsi") >-1||//another kind of up. BrowserUseragent.indexof ("Qwap") >-1||//Unknown Qwapper BrowserUseragent.indexof ("Jigs") >-1||//Unknown JigSaw BrowserUseragent.indexof ("Java") >-1||//Unknown Java based browserUseragent.indexof ("Alca") >-1||//unknown Alcatel-be3 browser (up based)Useragent.indexof ("MITS") >-1||//Unknown Mitsubishi BrowserUseragent.indexof ("mot-") >-1||//Unknown browser (up based)Useragent.indexof ("My S") >-1||//unknown Ericsson Devkit BrowserUseragent.indexof ("WAPJ") >-1||//Virtual Wapjag www.wapjag.deUseragent.indexof ("fetc") >-1||//fetchpage.cgi Perl script from Www.wapcab.deUseragent.indexof ("Alav") >-1||//yet another unknown up based browserUseragent.indexof ("Wapa") >-1||//another unknown browser (Web based "Wapalyzer")Useragent.indexof ("UCWEB") >-1||//another unknown browser (Web based "Wapalyzer")Useragent.indexof ("BlackBerry") >-1||//another unknown browser (Web based "Wapalyzer")Useragent.indexof ("J2ME") >-1||//another unknown browser (Web based "Wapalyzer")Useragent.indexof ("Oper") >-1)            {                return true; }            Else            {                return false; }        }

2. Consider ASP. NET MVC
There's a for mobile template.

3. Get the browser's properties

HttpBrowserCapabilities Bc=request.browser;            Response.Write ("<script language= ' JavaScript ' >alert ('" + BC. Browser + "');</script>");

4.js judgment

<script type= "Text/javascript" >varBro =navigator.useragent; //alert (bro);        //Alert (Bro.indexof ("Windows Phone"));        //ipad Browser navigator.useragent (ipad included)        if(Bro.indexof ("NetFront") > 0 | | bro.indexof ("UCWEB") > 0 | | bro.indexof ("iPhone") > 0 | | bro.indexof (" Windows CE ") > 0 | | Bro.indexof ("MIDP-2.0") > 0 | | Bro.indexof ("Android") > 0 | | Bro.indexof ("Opera Mini") > 0 | | Bro.indexof ("SymbianOS") > 0 | | Bro.indexof ("Windows Phone") > 0) {window.open ("Wap1/index.aspx", "_top"); }        //Else if (Bro.indexof ("Windows NT") > 0) {        //window.open ("newweb/default.html", "_top");        //        }                 Else{window.open ("Newweb/default.html", "_top"); }    </script>

(If there is a problem to the blogger website blog.uoolo.com or wuchao.cnblogs.com message)

Mobile version and PC version recognition

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.