user1386320
user1386320

Reputation:

How to prevent Finger-Touch (on touchscreens) with JavaScript?

Is it possible to prevent touch gestures on a TouchScreen monitors, tablets, phones using JavaScript?

Upvotes: 1

Views: 74

Answers (2)

Jack Pettinger
Jack Pettinger

Reputation: 2755

I have used a modified jQuery Block UI to do this in the past.

Upvotes: 1

Nate Higgins
Nate Higgins

Reputation: 2114

You can do it by preventing the touchstart event. You're probably looking to do it on the body if you're doing it page-wide.

var body = document.body;
element.ontouchstart = function(e) {
    e.preventDefault();
}

You can also use window.addEventListener for a page-wide affect.

window.addEventListener('touchstart', function(e) {
    e.preventDefault();
}

This will also allow others to hook into the touchstart event.

jQuery

It's also possible to do with jQuery, via the on method.

$('body').on('touchstart', function(e) {
    e.preventDefault();
});

Upvotes: 3

Related Questions