简体   繁体   English

网页如何确定用户是否有鼠标或触摸屏输入?

[英]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.

相关问题 如何使用JavaScript区分用户触摸的触摸板,触摸屏或鼠标 - How to Distinguish touchpad, touchscreen, or mouse which was touching by user, using JavaScript 如何确定用户是否在单个输入/字符串中包含时间? - How can I determine if a user has included a time in a single input/string? 我的网页如何判断用户是否扩大了视野? - How can my webpage tell if the user has enlarged their view? 如何检测用户鼠标移动的距离? - How can I detect the distance that the user's mouse has moved? 如何确定用户是否来自https domian? - How can I determine if a user has come from an https domian? 如何根据用户输入确定是否发生了更改事件? - How can I determine if change event occurred from user input? 如何确定用户或浏览器是否输入了表单上的数据? - How do I determine whether data on a form has been input by the user or the browser? 如何确定用户从服务器下载的网页中选择的输入字段 - How do I determine the input field the user has selected from a web page downloaded from a server p5.j​​s 的鼠标变量可以在触摸屏设备上使用吗? (Java 脚本) - Can mouse variables of p5.js be used on a touchscreen device? (JAVASCRIPT) 如何检查用户是否 idel 不使用我网页中的键盘和鼠标 - How to Check if user is idel not using Keyboard and Mouse from my webpage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM