目前,在我的JavaScript检测我用这个触摸屏设备:createTouch vs ontouchstart - 检测触摸屏设备的最佳方式?
if ('createTouch' in document) {
// do touchscreen-specific stuff
}
我看到很多开发人员使用ontouchstart
,像这样:
if ('ontouchstart' in document) {
// do touchscreen-specific stuff
}
是什么createTouch
和ontouchstart
之间的区别?哪一个是最安全的使用?还有其他一些简单而可靠的替代方案吗?