如何检测用户是否正在使用Windows平板电脑

时间:2016-04-04 13:18:00

标签: javascript jquery tablet

我的代码在Windows平板电脑上运行良好。我正在使用光滑滑块插件。如果用户正在使用触摸设备,则应将其停用。 我已经在Windows平板电脑上检查了我的网站,而不是“触摸”#34;我有这样的课程" no-touch" 这是我的代码

if( $('.no-touch').length ) {
    new Slider({
        element: '.theme-slider',
        slide: 'div',
        dots: false,
        infinite: false,
        arrows: true,
        slidesToShow: 2,
        slidesToScroll: 2,
    });
  }
});

如何检测我的网站是否以windows-tablet打开

4 个答案:

答案 0 :(得分:1)

也许这对你有用:

var isTouchDevice    = 'ontouchstart' in window || (navigator.msMaxTouchPoints>0);

来自:

Detecting Windows Tablet (touch windows devices) with Jquery

答案 1 :(得分:0)

使用javascript,您可以使用导航器对象:

var isms = navigator.platform; // win32 on mysystem

答案 2 :(得分:0)

没有任何直接的API调用来检测Windows是PC还是Tablet。 当您掌握它时,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);

答案 3 :(得分:0)

此代码在Surface,Edge浏览器

上返回true
if (window.navigator.pointerEnabled && navigator.maxTouchPoints > 1) {
    ...your function goes here...
}

你应该使用maxTouchPoints> 1,因为chrome在桌面上返回“1”。但是,触摸设备上的浏览器返回10