On Android, you can work out the current scaling by adding an absolute div to the body 100% wide and dividing the offset offsetWidth by window.innerWidth .
var iPadMeasureWidthNode = window.iPadWNode; if (!iPadMeasureWidthNode) { iPadMeasureWidthNode = window.iPadWNode = document.createElement('div'); // .ipad-measure-w {position:absolute; width:100%; top:-1px} iPadMeasureWidthNode.className = 'ipad-measure-w'; document.body.insertBefore(iPadMeasureWidthNode, document.body.firstChild); } var zoominverse = 1000 / Math.round(1000 * iPadMeasureWidthNode.offsetWidth / window.innerWidth);
You can save an element with a 1: 1 magnification by inverting (decreasing) the magnification scale:
// Not using scale3d because is hardware zooming which is ugly unreadable blurry pixel magnification. node.style.webkitTransform = (zoominverse > 1) ? 'scale(' + zoominverse + ')' : ''; node.style.webkitTransformOrigin = (zoominverse > 1) ? '0 0 0' : '';
Resizing is detected by the window.onresize event (although the resizing event is delayed until resizing is completed ... you can detect the start of scaling using the gesturestart event on the iPad or the document.touchstart event and detect 2 fingers down).
Edit: after three corrections saying that this does not work, I thought it was better to add an example showing that it works. Tests: Android 4.1.2 regular browser, Android 4.1.2 Chrome, Android Opera Mobile 12.10, iPad 2 iOS4. (Does not work on Android Firefox Mobile and will not work in iframes, so jsfiddle will not work).
<!DOCTYPE html> <html> <head> <style> .ipad-measure-w { position: absolute; width: 100%; top: -1px; }; </style> </head> <body> <button onclick="alertWidth()">alertWidth</button> <div style="width: 1600px; height: 100px; background-color: blue;"></div> <script> function alertWidth() { var iPadMeasureWidthNode = window.iPadWNode; if (!iPadMeasureWidthNode) { iPadMeasureWidthNode = window.iPadWNode = document.createElement('div'); iPadMeasureWidthNode.className = 'ipad-measure-w'; document.body.insertBefore(iPadMeasureWidthNode, document.body.firstChild); } var zoominverse = 1000 / Math.round(1000 * iPadMeasureWidthNode.offsetWidth / window.innerWidth); alert(zoominverse); } </script> </body> </html>
source share