178

I've update my iPhone 6 plus to iOS 10 beta version and just found that in mobile safari, you can zoom any webpages by double tapping or pinching IGNORE the user-scalable=no code in the meta tag. I don't know whether it's a bug or feature. If it's considered as a feature, how do we disable viewport zooming iOS 10 safari ?


updated on iOS 11/12 release, iOS 11 and iOS 12 safari still DO NOT respect the user-scalable=no meta tag.

mobile github site on Safari

Sam Su
  • 4,585
  • 6
  • 31
  • 74
  • 2
    An accessibility feature: Of note in Safari on iOS 10 http://twitter.com/thomasfuchs/status/742531231007559680/photo/1 – ErikE Jun 14 '16 at 10:37
  • 99
    No, it isn't. It is bad practice for normal web content. For web apps, the default zoom behavior can completely ruin usability. For example, nobody wants to zoom in on a channel up button because they tapped it twice, nor zoom in on part of a video game because they tapped the jump button twice. There's a reason that this feature was added in the first place, and it makes no sense to break usability for everybody just because a few "web designers" don't know what they're doing. Go scream at the site designers and quit breaking the browser. – dgatwood Jan 30 '17 at 08:10
  • 49
    Saying it's "bad practice" is an opinion and doesn't change the fact that Apple is insistent on taking web standards that the community spends months/years/decades getting implemented cross platform and taking a giant crap on them. Why should Apple dictate that web designers don't know what they're doing? Terrible argument. – samrap Feb 09 '17 at 23:36
  • 2
    Personally, I think this stems from boilerplate code online where devs just copy and paste blindly without knowing what the purpose of the code is. – William Isted Mar 01 '17 at 10:15
  • 8
    Answer is simple, Apple: make disabling the meta tag a default-off accessibility setting. Those who need it, will have it, without punishing those who don't. – Ruben Martinez Jr. Apr 19 '17 at 23:56
  • Have a look at my answer at the bottom of this page - my solution is a mix of other answers and my own invention. – Piotr Kowalski Jul 27 '17 at 14:02
  • Can someone confirm that none of the answers works on iOS 11 anymore? – Mick Jul 17 '18 at 15:49
  • I can confirm that its not working in iOS 12 ... sadly. – TJR Jan 07 '19 at 13:32
  • 1
    Apple shames the developer for not being accessible yet uses the tiniest font for everything. And if you use the accessibility features built into the os like making the font bigger it breaks the layout and sometimes even functionality. Such A-holes. I think it has more to do with trying to destroy web apps to force people into building apps they serve people through the apple store. Apple is the new Microsoft, remember IE6 - IE8. – pathfinder Feb 21 '19 at 04:26

18 Answers18

98

It's possible to prevent webpage scaling in safari on iOS 10, but it's going to involve more work on your part. I guess the argument is that a degree of difficulty should stop cargo-cult devs from dropping "user-scalable=no" into every viewport tag and making things needlessly difficult for vision-impaired users.

Still, I would like to see Apple change their implementation so that there is a simple (meta-tag) way to disable double-tap-to-zoom. Most of the difficulties relate to that interaction.

You can stop pinch-to-zoom with something like this:

document.addEventListener('touchmove', function (event) {
  if (event.scale !== 1) { event.preventDefault(); }
}, false);

Note that if any deeper targets call stopPropagation on the event, the event will not reach the document and the scaling behavior will not be prevented by this listener.

Disabling double-tap-to-zoom is similar. You disable any tap on the document occurring within 300 milliseconds of the prior tap:

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

If you don't set up your form elements right, focusing on an input will auto-zoom, and since you have mostly disabled manual zoom, it will now be almost impossible to unzoom. Make sure the input font size is >= 16px.

If you're trying to solve this in a WKWebView in a native app, the solution given above is viable, but this is a better solution: https://stackoverflow.com/a/31943976/661418. And as mentioned in other answers, in iOS 10 beta 6, Apple has now provided a flag to honor the meta tag.

Update May 2017: I replaced the old 'check touches length on touchstart' method of disabling pinch-zoom with a simpler 'check event.scale on touchmove' approach. Should be more reliable for everyone.

Community
  • 1
  • 1
Joseph
  • 2,809
  • 19
  • 11
  • 3
    Note that touchstart hack is inconsistent... and if you manage to sidestep it you are stuck in a very uncomfortable state – Sam Saffron Sep 14 '16 at 21:32
  • I agree with @Joseph regarding the statement that Apple should reconsider/allow developers to bypass this for interactive mobile web experiences that don't even benefit from zooming in any capacity. – JackCA Sep 16 '16 at 03:04
  • 5
    Eg. full screen mapping apps, there is a zoom feature hard coded in the mapping application (Google Maps JS, Leaflet etc.). Google advices to add a meta tag `` and if browser doesn't respect the meta tag, it is very bad browser design. The other this like very bad design is back/forward action by sliding, which cannot be prevented in iOS 9/10. It breaks severely dragging actions inside web application. – Timo Kähkönen Oct 13 '16 at 18:36
  • Both hacks do not work with iOS 10.1.1 when double-tapping or pinch-zooming an image. They prevent these actions happening on text, but images seem to be excluded? – Reado Nov 28 '16 at 11:42
  • 4
    If user start dragging with one finger then put a second finger on the screen will be able to pinch-zoom. You can disable both zoom and scroll with a `preventDefault` on `touchmove`. You can't (completely) disable zoom without disabling scroll. – Paolo Dec 12 '16 at 22:52
  • 13
    Wow, this part (I'll paste here) was SUPER helpful to me. I haven't seen this mentioned by anyone else ANYWHERE on the internet. It took me hours to fix this problem. I'm really disappointed in Apple's UX design choices about this, where forms auto-zoom-in but then don't zoom back out. `If you don't set up your form elements right, focusing on an input will auto-zoom, and since you have mostly disabled manual zoom, it will now be almost impossible to unzoom. Make sure the input font size is >= 16px.` – Ryan Jan 30 '17 at 18:13
  • Thanks, It is helpful for me. – Ramesh kumar Apr 26 '17 at 10:14
  • 1
    This is what finally disabled the double-tap zoom for me. Although, I found with the 300ms span, a slower double-tap would still register. Increasing the gap to 500ms worked for me. Thanks! – pilar1347 Sep 05 '17 at 20:25
  • Can you point me to the MDN doc that describes `event.scale`. I'm using typescript and I can't resolve the event type. I have found https://developer.mozilla.org/en-US/docs/Web/API/GestureEvent but it's marked as a non-standard API. – Stewart Apr 09 '18 at 05:38
  • 2
    @Stewart Yeah, it's iOS-specific. But so is this question. – Joseph Apr 10 '18 at 23:33
  • Why don't you use `gesturestart` instead touchmove with if clause? You would safe performance by not having a if clause, or is there any reason to do so? – Mick Aug 06 '18 at 10:43
  • The only problem is pinch zoom works while scrolling: To reproduce scroll slightly with one finger and then pinch with the other -> Zoom works and preventDefault() has no effect. – Mick Aug 06 '18 at 10:56
  • 6
    It seems that this isnt working in iOS 12 anymore. Any idea how to make this work for iOS 12? – TJR Jan 07 '19 at 13:33
  • 2
    I am certain it would have been a lot less code for apple to just add a switch in safari or accessibility settings that overrides the user-scalable meta tag, which would much more truly improve accessibility. They should also have a switch to turn off zoom and double-tap to zoom for folks who have parkinsons. We should all be shaming apple for using accessibility as a reason to push more people into apps only "accessible" in their web store. They don't really give a rats @ss about anything but profit. – pathfinder Feb 21 '19 at 05:41
  • Note that if you ever want to remove this event listener (e.g. you disable default behavior only for a temporal interaction), you also have to pass `false` (or `{ capture: true }`) as the last argument to `removeEventListener`: `document.removeEventListener('touchmove', yourFunction, false)`. Struggled with this for a bit myself as page stopped scaling and scrolling forever after one interaction – Alexey Grinko Mar 23 '19 at 10:52
  • Setting the font size to 16px was the fix for me – Jamie Burton May 23 '19 at 09:28
  • 2
    iOS 13 change false to {passive: false} – wayofthefuture Dec 23 '19 at 16:23
80

This is a new feature in iOS 10.

From the iOS 10 beta 1 release notes:

  • To improve accessibility on websites in Safari, users can now pinch-to-zoom even when a website sets user-scalable=no in the viewport.

I expect we're going to see a JS add-on soon to disable this in some way.

Paul Gerarts
  • 1,046
  • 8
  • 9
  • 3
    This is bad... How can we make them change their mind?... why would you get UI designers then when your webapp breaks because of this. – Onza Jul 15 '16 at 07:42
  • Why would anything break? It is a viewport zoom, it is used so users can read webpages on small devices. It doesn't affect the UI. – Karlth Jul 16 '16 at 00:31
  • 4
    @Onza: I don't think it's bad. I think it's good. Disabling pinch / zooming (default user behaviour) is considered bad, and a lot of mobile websites do it. The only acceptable user case would be a real web app that looks and feels like an app. – wouterds Aug 03 '16 at 15:14
  • For some reason this causes that when you are clicking buttons it'll zoom, my buttons are the right size, I don't want them to zoom. – Onza Aug 10 '16 at 08:04
  • @Onza Buttons shouldn't trigger zoom unless you are double tapping them. Input fields do cause a zoom action when the keyboard and typing cursor appear. – Paul Gerarts Sep 07 '16 at 15:13
  • @Onza If you have a button that requires multiple taps in short intervals you can use javascript to catch the touch events. – Paul Gerarts Sep 07 '16 at 15:14
  • 6
    Bad.. I change viewport using js and block zoom only when some elements are selected on the website now it is broken due to this "decision". If someone decide to block it - there is a reason. – Zhenya Sep 14 '16 at 17:33
  • 11
    @Karlth it's very bed for a game developer – Sandeep Sep 21 '16 at 09:32
  • @Sandeep Why? (I'm a part time game developer). If the user decides to zoom into a part of the screen, why would that affect the game? It might affect his gameplay but not the code - it is just zooming handled by the device. It is just like taking a magnifying glass from a book reader - it doesn't change anything. – Karlth Sep 21 '16 at 10:21
  • This is outdated. See Cellanes answer. iOS 10 now does support user-scalable=no – Felix Sep 21 '16 at 15:18
  • 15
    I have IOS 10.0.2, user-scalable=no does not disable zooming anymore on our website... Our main issue with zooming is with our fixed side menu.. It just breaks the layout.. Any ideas or solutions on this? I understand zooming is good for accessibility, we made zooming available on specific parts of our site using js events (hammer) & css.. I don't see why a rule has to be imposed on everyone, seems like the PC Police is starting to take over our dev world as well?! – webkit Sep 29 '16 at 10:31
  • 54
    "The only acceptable user case would be a real web app that looks and feels like an app." - and this is, like you said, a real, acceptable use case, that isn't *that* rare.. – Florrie Nov 01 '16 at 03:45
  • 1
    For "apps" we should be able to prevent double-tap to zoom. Double tap occurs *unintentionally* for normal users e.g. tapping a + button twice, tapping a list item twice. Note that the double-tap zoom also re-introduces the 300ms delay between touchend and click (fixed in iOS9 and broken again in iOS10 - a non-zoomable page in iOS9 has zero delay and iOS10 adds that delay back in again - arrgh!). Accessability is fine if pinch to zoom allowed. Focusing an input with a small font size causing automatic zoom is also sensible for accessability. Double-tap zoom *breaks* accessability for tremors. – robocat Mar 07 '17 at 01:54
  • 3
    I have an web app that I want to look & feel like a "real app" -- and this Safari ignore-ence (pun intended) completely messes the UX up. What a dumb move on Safari's part. – Jason FB Mar 10 '17 at 01:10
  • @webkit On of the reason it breaks layout is because after zooming in window.innerWidth and window.innerHeight change (while document width / height remain the same) and fixed elements got repositioned to new window size. This occured till iOS 10.2, in new update iOS 10.3, this "feature" is dropped and fixed elements are aligned to document, not zoom-adjusted window size. Still we need to take care of touch events (e.g. intercepted by hammer) though. It's probably best to just disable all swipe / pan / pinch events (like galleries) when window is zoomed-in to allow user pan zoomed-in site. – Andrzej Dąbrowski Apr 25 '17 at 14:51
  • 1
    They should have made this an option in the accessibility menu, so it's still an option but for the other 99% of the users not the default behaviour. – Dirk Boer May 12 '17 at 11:11
  • @DirkBoer I have to disagree with you. Apple is trying to make their products appealing for everyone. This includes people with poor-sight, a huge portion of them are the elderly. Those people rely on the it-just-works-out-of-the-box'ness of the devices. These are not people that are going to find the "allow me to zoom everywhere" feature. People with niche disabilities know to search for help-me features, those are the ones you find in Accessibility. - From Apple's perspective, I understand why they did it this way. - Is what I'm trying to say. – Paul Gerarts May 13 '17 at 16:05
  • Hi Paul, I understand what you're saying. I think it's rather arbitrary though, because all 'navtive' apps won't zoom in anyway if you don't go to the accesibility menu explicitly. – Dirk Boer May 15 '17 at 10:11
  • @DirkBoer well-implemented apps scale with the system-font size slider if I'm not mistaken. But again, then why not just decrease the perceived screen width in the browser if we increase the font-size (effectively scaling-up the website's UI). Responsive sites should be able to handle abuse like this. That seems like a nice solution to me anyway. – Paul Gerarts May 15 '17 at 20:31
  • @DirkBoer System-font size slider is very easy to find since it is (almost) accessible from the main settings page. Pinching is also something we expect to work in the browser, because it usually does. So the fact that it would suddenly not work could be considered confusing behaviour. – Paul Gerarts May 15 '17 at 20:36
  • 1
    It's bad for map applications where pinch zooming is important. – MichaelG May 07 '21 at 20:05
23

I've been able to fix this using the touch-action css property on individual elements. Try setting touch-action: manipulation; on elements that are commonly clicked on, like links or buttons.

iainbeeston
  • 1,643
  • 18
  • 20
  • 1
    "manipulation" doesn't prevent pinch zoom, only double-tap zoom. – Moos Feb 14 '17 at 00:41
  • 4
    This should be the accepted answer. you can use `touch-action: none;` to control all the gestures yourself. – Guy Sopher Aug 06 '17 at 11:13
  • 5
    this is great - disabling double-tap zooming while leaving pinch zooming, which SHOULD be considered a gesture - double tapping should not. 1 dog is a dog. 1 dog + 1 dog does not a space shuttle make. It makes 2 dogs, and they do things that you'd expect 2 dogs to do. I have never expected 2 dogs to be a space shuttle. Never. – Larry Oct 13 '17 at 14:29
  • 5
    @GuySopher iOS does *not* provide `touch-action: none` only `manipulatoin`, which leaves the pinch-zoom problem as it is. – humanityANDpeace Nov 01 '18 at 08:12
  • use touch-action: pan-x pan-y, fixes it. – Husky931 Dec 28 '20 at 05:42
20

The workaround that works in Mobile Safari at this time of writing, is to have the the third argument in addEventListener be { passive: false }, so the full workaround looks like this:

document.addEventListener('touchmove', function (event) {
  if (event.scale !== 1) { event.preventDefault(); }
}, { passive: false });

You may want to check if options are supported to remain backwards compatible.

Chrillewoodz
  • 22,596
  • 18
  • 73
  • 147
Casper Fabricius
  • 1,049
  • 8
  • 19
14

It appears that this behavior is supposedly changed in the latest beta, which at the time of writing is beta 6.

From the release notes for iOS 10 Beta 6:

WKWebView now defaults to respecting user-scalable=no from a viewport. Clients of WKWebView can improve accessibility and allow users to pinch-to-zoom on all pages by setting the WKWebViewConfiguration property ignoresViewportScaleLimits to YES.

However, in my (very limited) testing, I can't yet confirm this to be the case.

Edit: verified, iOS 10 Beta 6 respects user-scalable=no by default for me.

Cellane
  • 480
  • 5
  • 16
  • 12
    10.0.1 here. Does not respect it. What is with Apple getting rid of features that everyone needs.. – lifwanian Sep 28 '16 at 02:34
  • 1
    This refers to `WKWebView` **not** to Safari. Source: One of our map apps broke and we have *no* idea how to fix it. – Fabio Poloni Sep 28 '16 at 12:18
  • Aha! Apologies, I came here when searching for solution for the same bug/feature in `WKWebView` and kind of assumed that the original question asked about `WKWebView` when writing my answer. So I suppose that during one of the first beta versions, Apple changed the behavior of both `WKWebView` and mobile Safari, then in beta 6, they reverted the behavior of `WKWebView` but kept it for the mobile Safari. – Cellane Sep 29 '16 at 13:00
  • 1
    10.0.2 does not respect `user-scalable=no`. I'm not sure why they would ever undo this, only to bring it back, only to remove it again. – Aidan Hakimian Oct 15 '16 at 13:35
8

I spent about an hour looking for a more robust javascript option, and did not find one. It just so happens that in the past few days I've been fiddling with hammer.js (Hammer.js is a library that lets you manipulate all sorts of touch events easily) and mostly failing at what I was trying to do.

With that caveat, and understanding I am by no means a javascript expert, this is a solution I came up with that basically leverages hammer.js to capture the pinch-zoom and double-tap events and then log and discard them.

Make sure you include hammer.js in your page and then try sticking this javascript in the head somewhere:

< script type = "text/javascript" src="http://hammerjs.github.io/dist/hammer.min.js"> < /script >
< script type = "text/javascript" >

  // SPORK - block pinch-zoom to force use of tooltip zoom
  $(document).ready(function() {

    // the element you want to attach to, probably a wrapper for the page
    var myElement = document.getElementById('yourwrapperelement');
    // create a new hammer object, setting "touchAction" ensures the user can still scroll/pan
    var hammertime = new Hammer(myElement, {
      prevent_default: false,
      touchAction: "pan"
    });

    // pinch is not enabled by default in hammer
    hammertime.get('pinch').set({
      enable: true
    });

    // name the events you want to capture, then call some function if you want and most importantly, add the preventDefault to block the normal pinch action
    hammertime.on('pinch pinchend pinchstart doubletap', function(e) {
      console.log('captured event:', e.type);
      e.preventDefault();
    })
  });
</script>
brandito
  • 646
  • 7
  • 19
sporker
  • 143
  • 1
  • 2
  • 9
  • I've also been trying to solve this problem when working with hammer.js, and can confirm that I could prevent the viewport zoom by adding a `.preventDefault` to all the hammer gesture handlers. I'm using swipe/pinch/pan/tap together, i've added it to all the handlers, i don't know whether there's a specific one that's doing the job. – Conan Oct 19 '16 at 14:16
7

In my particular case, I am using Babylon.js to create a 3D scene and my whole page consists of one full screen canvas. The 3D engine has its own zooming functionality but on iOS the pinch-to-zoom interferes with that. I updated the the @Joseph answer to overcome my problem. To disable it, I figured out that I need to pass the {passive: false} as an option to the event listener. The following code works for me:

window.addEventListener(
    "touchmove",
    function(event) {
        if (event.scale !== 1) {
            event.preventDefault();
        }
    },
    { passive: false }
);
Hamed
  • 1,091
  • 6
  • 21
  • My use case is also a full page 3d scene with custom pinch controls. I would have been sunk if there wasn't a workaround to Apple explicitly ignoring the user-scale: no meta. – Nick Bilyk Oct 07 '18 at 13:54
  • 1
    Life-saver - This is the only solution that works for me as of iOS 14.4.2 that still allows for multi-touch being registered - My use-case being a web game that uses joystick controls for mobile. – David Bradbury Apr 27 '21 at 20:05
6

I tried the previous answer about pinch-to-zoom

document.documentElement.addEventListener('touchstart', function (event) {
    if (event.touches.length > 1) {
        event.preventDefault();
    }
}, false);

however sometime the screen still zoom when the event.touches.length > 1 I found out the best way is using touchmove event, to avoid any finger moving on the screen. The code will be something like this:

document.documentElement.addEventListener('touchmove', function (event) {
    event.preventDefault();      
}, false);

Hope it will help.

Chihying Wu
  • 69
  • 1
  • 3
6

Check for scale factor in touchove event then prevent touch event.

document.addEventListener('touchmove', function(event) {
    event = event.originalEvent || event;
    if(event.scale > 1) {
        event.preventDefault();
    }
}, false);
Parmod
  • 1,127
  • 1
  • 9
  • 16
6

We can get everything we want by injecting one style rule and by intercepting zoom events:

$(function () {
  if (!(/iPad|iPhone|iPod/.test(navigator.userAgent))) return
  $(document.head).append(
    '<style>*{cursor:pointer;-webkit-tap-highlight-color:rgba(0,0,0,0)}</style>'
  )
  $(window).on('gesturestart touchmove', function (evt) {
    if (evt.originalEvent.scale !== 1) {
      evt.originalEvent.preventDefault()
      document.body.style.transform = 'scale(1)'
    }
  })
})

✔ Disables pinch zoom.

✔ Disables double-tap zoom.

✔ Scroll is not affected.

✔ Disables tap highlight (which is triggered, on iOS, by the style rule).

NOTICE: Tweak the iOS-detection to your liking. More on that here.


Apologies to lukejackson and Piotr Kowalski, whose answers appear in modified form in the code above.

Jeff McMahan
  • 1,226
  • 12
  • 15
  • This works on my iPad emulator which is running iOS 11.2. On my real iPad running iOS 11.3 it doesn't work. I added a console.log to make sure the events are fired and so they appear in the console. It is something to do with iOS 11.3 ? Or with real devices ? – Mathieu R. Apr 18 '18 at 03:33
  • 1
    @MathieuR. It is an iOS 11.3 issue. It can be rectified by using one of the `addEventListener` based answers and passing `{ passive: false }` as the `options` parameter instead of `false`. However, for backward compatibility you need to pass `false` unless the `passive` option field is supported. See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners – Josh Gallagher May 17 '18 at 17:31
  • @JoshGallagher Could you provide a working example? On iOS11 none of the answers is working for me. – Mick Jul 17 '18 at 15:53
  • The 'gesturestart' -> preventDefault works for me at time of writing on iOS 12,2 – Michael Camden Jul 18 '19 at 13:43
6

I came up with a pretty naive solution, but it seems to work. My goal was to prevent accidental double-taps to be interpreted as zoom in, while keeping pinch to zoom working for accessibility.

The idea is in measuring time between the first touchstart and second touchend in a double tap and then interpreting the last touchend as click if the delay is too small. While preventing accidental zooming, this method seems to keep list scrolling unaffected, which is nice. Not sure if I haven't missed anything though.

let preLastTouchStartAt = 0;
let lastTouchStartAt = 0;
const delay = 500;

document.addEventListener('touchstart', () => {
  preLastTouchStartAt = lastTouchStartAt;
  lastTouchStartAt = +new Date();
});
document.addEventListener('touchend', (event) => {
  const touchEndAt = +new Date();
  if (touchEndAt - preLastTouchStartAt < delay) {
    event.preventDefault();
    event.target.click();
  }
});

Inspired by a gist from mutewinter and Joseph's answer.

Alexander Kachkaev
  • 741
  • 10
  • 26
5

As requested, I have transfered my comment to an answer so people can upvote it:

This works 90% of the time for iOS 13:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, user-scalable=no, shrink-to-fit=no" />

and

<meta name="HandheldFriendly" content="true">

Sterling Bourne
  • 2,390
  • 20
  • 20
1

As odd as it sounds, at least for Safari in iOS 10.2, double tap to zoom is magically disabled if your element or any of its ancestors have one of the following:

  1. An onClick listener - it can be a simple noop.
  2. A cursor: pointer set in CSS
mariomc
  • 853
  • 1
  • 9
  • 13
  • how about pinching? – Sam Su Jan 14 '17 at 02:41
  • Unfortunately, pinch to zoom is not covered by this solution. For that, we used the solution proposed in: http://stackoverflow.com/a/39594334/374196 – mariomc Jan 17 '17 at 11:42
  • Doesn't work for me. I am using 10.2.1 Beta 4 on an iPod Touch using this test page and double tapping any of the grey squares zooms: https://jsbin.com/kamuta/quiet – robocat Jan 22 '17 at 23:46
  • 1
    I have this on a span in a react app and it does not work. – Fasani Feb 12 '17 at 13:16
1

Unintentional zooming tends to happen when:

  • A user double taps on a component of the interface
  • A user interacts with the viewport using two or more digits (pinch)

To prevent the double tap behaviour I have found two very simple workarounds:

<button onclick='event.preventDefault()'>Prevent Default</button>
<button style='touch-action: manipulation'>Touch Action Manipulation</button>

Both of these prevent Safari (iOS 10.3.2) from zooming in on the button. As you can see one is JavaScript only, the other is CSS only. Use appropriately.

Here is a demo: https://codepen.io/lukejacksonn/pen/QMELXQ

I have not attempted to prevent the pinch behaviour (yet), primarily because I tend not to create multi touch interfaces for the web and secondly I have come round to the idea that perhaps all interfaces including native app UI should be "pinch to zoom"-able in places. I'd still design to avoid the user having to do this to make your UI accessible to them, at all costs.

lukejacksonn
  • 445
  • 6
  • 9
1

Found this simple work around which appears to prevent double click to zoom:

    // Convert touchend events to click events to work around an IOS 10 feature which prevents
    // developers from using disabling double click touch zoom (which we don't want).
    document.addEventListener('touchend', function (event) {
        event.preventDefault();
        $(event.target).trigger('click');
    }, false);
Syntax
  • 2,039
  • 2
  • 21
  • 33
0

I checked all above answers in practice with my page on iOS (iPhone 6, iOS 10.0.2), but with no success. This is my working solution:

$(window).bind('gesturestart touchmove', function(event) {
    event = event.originalEvent || event;
    if (event.scale !== 1) {
         event.preventDefault();
         document.body.style.transform = 'scale(1)'
    }
});
Piotr Kowalski
  • 328
  • 3
  • 14
0

this worked for me:

document.documentElement.addEventListener('touchmove', function (event) {
    event.preventDefault();
}, false);
  • I tried this, it did prevent pinch zooming, however it disables touch scrolling of the viewport so you cannot scroll the page up and down anymore. – TGR Jun 14 '20 at 05:48
0

In the current version of safari this is not working anymore. You have to define the second parameter as non-passive by passing {passiv:false}

 document.addEventListener('touchmove', function(e) {
 e.preventDefault();
}, { passive: false });
Silicium
  • 275
  • 5
  • 15