Reputation: 443
How can I prevent zooming of the browser on double click in Google Chrome when the desktop site is enabled. I tried adding <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
, but it didn't work. And I also tried adding the event.preventDefault()
method on window.ondblclick
event, but this too didn't work.
So how can I do it?
Upvotes: 0
Views: 1202
Reputation: 61
Try the following code:
let time_stamp = 0; // Or Date.now()
window.addEventListener("touchstart", function(event_) {
if (event_.timeStamp - time_stamp < 300) { // A tap that occurs less than 300 ms from the last tap will trigger a double tap. This delay may be different between browsers.
event_.preventDefault();
return false;
}
time_stamp = event_.timeStamp;
});
Upvotes: 1