简体   繁体   中英

How to detect browser in Ember

Does Ember have built-in way to detect browser? Something like this if using this library(bowser)

    if (bowser.msie) {
        ...
    } else if (bowser.gecko) {
        ...
    } else if (bowser.webkit) {
        ...
    }

Or, I can just npm install bowser , then import it and use it in Ember

I guess there won't be any builtin way in ember to detect browser AFAIK. Usually this kind of job will be delegated to ember addon, may be try ember-browser-checker if this is not fulfilled your requirement then you can consider any npm/bower libraries like you found bowser .

我实现了一点浏览器检查, 因为服务意识到这不安全,但适用于简单的需求

Ember UserAgent is an Ember addon which exposes a userAgent service, making it easy to detect browser, device, OS and more.

It works in both browser & Fastboot environments and is as simple as:

const userAgent = this.get('userAgent');

userAgent.get('browser.isChrome'); // Boolean
userAgent.get('engine.isWebKit'); // Boolean
userAgent.get('os.info'); // => { name: 'Ubuntu', version: '11.10' }
userAgent.getDevice(); // => { model: 'iPhone 7', type: 'mobile', vendor: 'Apple'}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM