Detect between a mobile browser or a PhoneGap application

后端 未结 16 1972
小蘑菇
小蘑菇 2020-11-28 03:03

Is it possible to detect if the user is accessing through the browser or application using JavaScript?

I\'m developing a hybrid application to several mobile OS thr

16条回答
  •  盖世英雄少女心
    2020-11-28 03:18

    New solution:

    var isPhoneGapWebView = location.href.match(/^file:/); // returns true for PhoneGap app
    

    Old solution:
    Use jQuery, run like this

    $(document).ready(function(){
       alert(window.innerHeight);
    });
    

    Take iPhone as example for your mobile application,

    When using PhoneGap or Cordova, you'll get 460px of WebView, but in safari, you'll lose some height because of browser's default header and footer.

    If window.innerHeight is equal to 460, you can load phonegap.js, and call onDeviceReady function

提交回复
热议问题