How to detect if I am in browser (local development) in Ionic 2

前端 未结 7 1163
太阳男子
太阳男子 2020-12-03 03:00

I want to make sure to launch inappbrowser only if I am on devices (iOs, Android...), but if I am in browser (local development mode or just a Web App with gulp build), I wa

相关标签:
7条回答
  • 2020-12-03 03:28

    I have faced the same problem in an Ionic 3 application and found here a nice method of checking if the application runs in a browser vs. real device/emulator:

    isApp = !document.URL.startsWith('http');
    

    Basically it relies on the fact that real devices or emulators serve resources using file protocol rather than http, as used by the browsers.

    0 讨论(0)
提交回复
热议问题