![](/img/trans.png)
[英]How to detect whether the user is using mobile, tablet or desktop and redirect them?
[英]how to detect if user is using windows tablet
我的代码在Windows平板电脑上运行不正常。 我正在使用光滑滑块插件。 如果用户正在使用触摸设备,则应将其停用。 我在Windows平板电脑上检查了我的网站,而不是“触摸”课程,我有“不接触”这里是我的代码
if( $('.no-touch').length ) {
new Slider({
element: '.theme-slider',
slide: 'div',
dots: false,
infinite: false,
arrows: true,
slidesToShow: 2,
slidesToScroll: 2,
});
}
});
如何检测我的网站是否与Windows平板电脑一起打开
也许这对你有用:
var isTouchDevice = 'ontouchstart' in window || (navigator.msMaxTouchPoints>0);
从:
使用javascript,您可以使用navigator对象:
var isms = navigator.platform; // win32 on mysystem
没有任何直接的API调用来检测Windows是PC还是平板电脑。 当您掌握它时,Microsoft Surface Pro可以是平板电脑,当您将它连接到鼠标并放入桌面时,它可以是笔记本电脑。
如果您使用带鼠标的窗口,那么它就是一台PC! 如果您使用不带鼠标的Windows,那么它就是平板电脑。
没有功能可以检测用户是否连接了鼠标,但这里有解决方法:
var Mousefound = false;
function MouseActivity(e) {
window.removeEventListener('mousemove', MouseActivity, false);
Mousefound = true;
// enable your slick-slider plugin
}
window.addEventListener('mousemove', MouseActivity, false);
此代码在Surface,Edge浏览器上返回true
if (window.navigator.pointerEnabled && navigator.maxTouchPoints > 1) {
...your function goes here...
}
你应该使用maxTouchPoints> 1,因为chrome在桌面上返回“1”。 但是,触摸设备上的浏览器返回10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.