View Sidebar
Detecting touch events on window tablet for internet explorer

Detecting touch events on window tablet for internet explorer

May 14, 2017 17:13

With the large range of devices and browsers in the market today its very difficult to make your code compatible for all. We often come across one such device and browser where the code wont work.

Recently while developing an edetailing application for window tablet we found out that the usually used touchstart and click event are not detected on internet explorer for windows tablets. They dont even work on my windows 8 tocuh screen laptop.

The solution was to add a “pointerdown” event along with click and touchstart. The pointerdown event is fired for mouse, touch and stylus pen too. Interestingly it doesnt support Safari browser on Desktop and Firefox and Android for Mobile Devices.

Check out the code below

targetElement.addEventListener(“pointerdown”, function(e) {
// Process the event

If there are multiple targets with same action

targetElementGroup = document.getElementsByClassName(CLASSNAME);
for (var i=0; i<targetElementGroup.length; i++) {
targetElementGroup[i].addEventListener(‘pointerdown’, function(e) {
//Process the event
}, false);

If you like the article please share

Leave a reply

You must be logged in to post a comment.