Detect Zoom Level

Currently there is no way to detect the zoom level with Javascript reliably.

That would be useful in many situations.

The current state is a complete mess;

Could you describe the main use-cases?

My specific use case is to avoid gesture detection (with touch events) when the page is zoomed-in, otherwise the user sometime accidentally triggers a swipe or other gestures. There are certainly many other use cases… The browser could simply make that value available to the app… why not? It should be very simple. Otherwise there are hundreds of workarounds that don’t work or work only on a single browser -.-

I think the Visual Viewport API can be used to detect when the page is zoomed. Please take a look.

1 Like

Wow, thanks! window.visualViewport.scale seems exactly what I need. Tested on Chrome and Safari and it works. Unfortunately its browser support is still partial, but it is certainly the right solution for the future.