JS to determine whether the Pc,ios,android client

Source: Internet
Author: User

Write in front

Using HTML5 in a project requires a different approach to the client browser, which requires that the useragent in the request be parsed and processed.

An example
<%@ Page Language="C #"AutoEventWireup="true"codebehind="Default.aspx.cs"Inherits="Wolfy.RedirectDemo.Default" %><!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server">    <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    <title></title></Head><Body>    <formID= "Form1"runat= "Server">        <DivID= "MSG">        </Div>    </form></Body></HTML><Script>    functionCheckclinetmodel () {//gets the useragent in the request header        varu=navigator.useragent; //whether it is an Android browser        varisandroid=U.indexof ('Android') > -1; //whether it is an iOS browser        varIsios= !!U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS X/); varmsg= "'; if(isandroid) {msg= "currently an Android client"; } Else if(Isios) {msg= 'currently an iOS client'; } Else{msg= 'is currently PC-side';        }; document.getElementById ("msg"). InnerHTML=msg;    }; Checkclinetmodel ();</Script>

For the adaptive page, you can add this meta

<name= "Viewport"  content= "Width=device-width, initial-scale=1 , maximum-scale=1, minimum-scale=1, user-scalable=no "/>

Test

Summarize

It is recorded here and will be used frequently in the future.

JS to determine whether the Pc,ios,android client

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.