PhoneGap: Detect if running on desktop browser

后端 未结 30 2825
时光取名叫无心
时光取名叫无心 2020-11-29 15:47

I\'m developing a web application that uses PhoneGap:Build for a mobile version and want to have a single codebase for the \'desktop\' and mobile versions. I want to be able

30条回答
  •  春和景丽
    2020-11-29 16:11

    Detect desktop browser even if emulate device is active

    Works in Windows and Mac machines. Need to find a solution for linux View details

    var mobileDevice = false;
    if(navigator.userAgent.match(/iPhone|iPad|iPod|Android|BlackBerry|IEMobile/))
        mobileDevice = true; 
    
    if(mobileDevice && navigator.platform.match(/Win|Mac/i))
        mobileDevice = false; // This is desktop browser emulator
    
    if(mobileDevice) {
        // include cordova files
    }
    

提交回复
热议问题