[英]how can a webpage determine if a user has mouse or touchscreen input?
If I have a webpage coded in html5 and javascript how can it detect what kind of input hardware the user has ? 如果我有一个用html5和javascript编码的网页,它将如何检测用户拥有哪种输入硬件? To give useful and correct instructions to them.
给他们有用和正确的指示。 A user may have mouse, touchscreen, both or full keyboard, limited keyboard on Smartphone ...etc.
用户可能拥有鼠标,触摸屏,全部或全部键盘,智能手机上的受限键盘...等。
I use this to avoid mouseover effects when I'm not sure. 我不确定时会用它来避免鼠标悬停的影响。
<script>
var hasMouse = false;
window.document.addEventListener('mouseover', mouseFound);
function mouseFound() {
hasMouse = true;
window.document.removeEventListener('mouseover', mouseFound);
console.log('found a mouse');
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.