PhoneGap: Detect if running on desktop browser

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

    Another way, based on SlavikMe's solution:

    Just use a query parameter passed to index.html from your PhoneGap source. Ie, in Android, instead of

    super.loadUrl("file:///android_asset/www/index.html");
    

    use

    super.loadUrl("file:///android_asset/www/index.html?phonegap=1");
    

    SlavikMe has a great list on where to do this on other platforms.

    Then your index.html can simply do this:

    if (window.location.href.match(/phonegap=1/)) {
      alert("phonegap");
    }
    else {
      alert("not phonegap");
    }
    

提交回复
热议问题