Analyzing the mobile terminal h5 page Android or IOS system

  Recently met a demand, the so-called app + web mixed-use development, we need to h5 built to APP, this time due to the different processing logic on Android and IOS, so we need to determine what, to the mobile terminal system what kind. Here we provide some type of judgment method, as follows:

function detect(){
    let equipmentType = "";
    let agent = navigator.userAgent.toLowerCase();
    let android = agent.indexOf("android");
    let iphone = agent.indexOf("iphone");
    let ipad = agent.indexOf("ipad");
    if(android != -1){
        equipmentType = "android";
    }
    if(iphone != -1 || ipad != -1){
        equipmentType = "ios";
    }
    return equipmentType;
}

  

  In the above method, the return value is compared android Android system, the return value is compared ios IOS system. End Analyzing model, a corresponding operation can be performed up.

IF (Detect () === 'Android') { 
    // page Android mobile end system to do something 


} the else IF (Detect () === 'iOS') { 
    // end of the page to the mobile system do IOS something 


}

  

 

Guess you like

Origin www.cnblogs.com/belongs-to-qinghua/p/12377147.html