How to detect platform using Ionic 4

前端 未结 8 1136
慢半拍i
慢半拍i 2021-02-09 08:24

How to detect browser and mobileweb platform using Ionic 4 because when I tried with below code in desktop browser it is not falling in ‘core’ condition.

<
8条回答
  •  花落未央
    2021-02-09 08:41

    For detecting the web platform you should use Bowser . I have used this in ionic 4 for detecting browser platform i.e whether it is safari or chrome.

    Step 1 : You need to install bowser in your project

    npm install bowser@2.7.0 --save-exact
    

    Step 2 : Then you need to import it in .ts page where you want to use it. let suppose home.ts

    import Bowser from "bowser";
    

    Step 3 : Then you need to write login to check browser platform inside a function in home.ts

    checkBrowserPlatform() {
      const browser = Bowser.getParser(window.navigator.userAgent);
      const browserName = browser.getBrowserName();
        console.log(browserName);
      }
    

    By calling checkBrowserPlatform() you can know the current browser name.

提交回复
热议问题