3

How can double-tap zoom be disabled on Safari mobile?

There are some rules for default behaviour: With text it somehow depends on font-size. Other types of elements also allow to be double tapped and usually perform a zoom then (e. g. img).

But the entire double-tap zoom should be disabled.

These were common approaches:

  • Applying touch-action: manipulation to *; does not work at all.
  • Applying touch-action: none to *; seems to disable zooming back out from the zoomed-in position…
  • <meta name="viewport" ...>; the browser ignores it.
  • Then, there were some JavaScript/jQuery solutions but none seemed to work at all or work reliably.

3 Answers 3

3
document.ondblclick = function (e) {
    e.preventDefault();
}

That's literally it. No special tricks needed lol. Tested on Safari iOS.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this: add user-scalable=no in your viewport meta tag, then use JavaScript to prevent double-tap zoom by tracking touchend events like this:

let lastTouchEnd = 0;
document.addEventListener('touchend', (event) => {
    const now = new Date().getTime();
    if (now - lastTouchEnd <= 300) event.preventDefault();
    lastTouchEnd = now;
}, false);

This combo blocks double-tap zoom on Safari without affecting pinch-to-zoom.

Comments

-1

Safari Mobile lacks a straightforward way to universally disable double-tap zoom. Typical approaches like touch-action: manipulation or user-scalable=no in the viewport meta tag often don’t work reliably on Safari Mobile. Here’s a JavaScript workaround to prevent double-tap zoom:

let lastTouchTime = 0;

document.addEventListener('touchend', (event) => {
    const currentTime = new Date().getTime();
    const tapLength = currentTime - lastTouchTime;

    if (tapLength < 500 && tapLength > 0) {
        event.preventDefault(); // Prevents double-tap zoom
    }

    lastTouchTime = currentTime;
});

This script stops double-tap zoom by treating consecutive taps within 500ms as invalid. Adjust the timing if necessary. This solution doesn't disable pinch-to-zoom, preserving accessibility.

3 Comments

Nice one! BTW, you might want to know that Date.now() is more verbose equivalent of new Date().getTime()
Thank you! Can you see that Stack & bing ,… use this hack?
@Adler It looks like this answer solved your problem. You may want to accept it and/or give poster the bounty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.