4

my code isn't function well on windows tablet. I'm using slick-slider plug-in. and it should be deactivated if user are using touch devices. I've inspected my site on windows tablet and instead of having "touch" class i have "no-touch" here is my code

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

how can i detect if my site is opend with windows-tablet

User1979
  • 817
  • 3
  • 13
  • 23

4 Answers4

1

Maybe this will work for you :

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

From:

Detecting Windows Tablet (touch windows devices) with Jquery

Community
  • 1
  • 1
E. R.
  • 46
  • 3
0

With javascript you can use navigator object:

var isms = navigator.platform; // win32 on mysystem
Jai
  • 74,255
  • 12
  • 74
  • 103
0

There is not any straightforward API call to detect if a Windows is PC or Tablet. Microsoft Surface Pro can be a tablet when you have it in your hand, and it can be a laptop when you connect it to your mouse and put in on table.

If you use a windows with mouse, then it is a PC! If you use a Windows without mouse, then it is a tablet.

There is no function to detect if user have mouse connected or not, but here is workaround:

var Mousefound = false;

function MouseActivity(e) {

  window.removeEventListener('mousemove', MouseActivity, false);
  Mousefound = true;

  // enable your slick-slider plugin

}

window.addEventListener('mousemove', MouseActivity, false);
Armin Nikdel
  • 315
  • 2
  • 9
0

this code returns true on Surface, Edge browser

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

you should use maxTouchPoints > 1, because chrome returns "1" on a desktop. However, browsers on touch devices returns 10