首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >检测到浏览器没有鼠标并且只支持触摸

检测到浏览器没有鼠标并且只支持触摸
EN

Stack Overflow用户
提问于 2011-10-20 23:53:09
回答 14查看 57.2K关注 0票数 163

我正在开发一个网页应用程序(不是一个有很多有趣的文本页面的网站),它有一个非常不同的触摸界面(点击时你的手指会隐藏屏幕)和鼠标(很大程度上依赖于悬停预览)。我怎样才能检测到我的用户没有鼠标来显示正确的界面呢?我打算给同时有鼠标和触摸屏的人留一个开关(就像一些笔记本电脑一样)。

浏览器中的触摸事件功能实际上并不意味着用户正在使用触摸设备(例如,Modernizr不支持它)。如果设备有鼠标,则正确回答问题的代码应返回false,否则返回true。对于带有鼠标和触摸屏的设备,它应该返回false (不仅仅是触摸屏)

顺便说一句,我的触摸界面可能也适用于只有键盘的设备,所以我想要检测的更多的是缺少鼠标。

为了更清楚地说明这一需求,下面是我希望实现的API:

代码语言:javascript
复制
// Level 1


// The current answers provide a way to do that.
hasTouch();

// Returns true if a mouse is expected.
// Note: as explained by the OP, this is not !hasTouch()
// I don't think we have this in the answers already, that why I offer a bounty
hasMouse();

// Level 2 (I don't think it's possible, but maybe I'm wrong, so why not asking)

// callback is called when the result of "hasTouch()" changes.
listenHasTouchChanges(callback);

// callback is called when the result of "hasMouse()" changes.
listenHasMouseChanges(callback);
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7838680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档