PhoneGap: Detect if running on desktop browser

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

    I was trying with the window objects but it didn't worked as I was opening the remote url in the InAppBrowser. Couldn't get it done. So the best and easiest way to achieve it was to append a string to the url which you need to open from the phonegap app. Then check if the document location has string appended to it.

    Below is the simple code for it

    var ref = window.open('http://yourdomain.org#phonegap', '_blank', 'location=yes');
    

    You will see a string is added to the url "#phonegap".So in the domain url add the following script

    if(window.location.indexOf("#phonegap") > -1){
         alert("Url Loaded in the phonegap App");
    }
    

提交回复
热议问题