PhoneGap: Detect if running on desktop browser

后端 未结 30 2869
时光取名叫无心
时光取名叫无心 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 15:55

    GeorgeW's solution is OK, but even on real device, PhoneGap.available is only true after PhoneGap's things has been loaded, e.g. onDeviceReady in document.addEventListener('deviceready', onDeviceReady, false) has been called.

    Before that time, if you want to know, you can do like this:

    runningInPcBrowser =
        navigator.userAgent.indexOf('Chrome')  >= 0 ||
        navigator.userAgent.indexOf('Firefox') >= 0
    

    This solution assumes that most developers develop using Chrome or Firefox.

提交回复
热议问题