How to detect device mode emulation?

前端 未结 3 768
广开言路
广开言路 2021-01-20 02:24

Referring to Chrome\'s ability to emulate device resolution and touch events: https://developer.chrome.com/devtools/docs/device-mode

The actual issue:



        
3条回答
  •  执念已碎
    2021-01-20 03:21

    I ended with:

    window.navigator.userAgent.indexOf('Mobile') !== -1;
    

    Chrome adds Mobile to userAgent in device emulation mode, for example "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1"

    'TouchEvent' in window && 'ontouchstart' in window

    isn’t providing correct state in real time when you turning on/off device mode unfortunately

提交回复
热议问题