iPad Zoom Issue on un-focussed tab in Safarai - ipad

I have a web page that doesn't (and shouldn't) allow zooming on the iPad. Everything works great, except in this scenario where multiple tabs are open in Safari:
1. have focus on my application's tab
2. change to a different tab
3. switch the iPad's orientation (i.e. portrait to landscape or vice versa)
4. switch back to my web apps tab
The iPad, in many instances, will have zoomed in and there is no way for me to reset the zoom. Since I have zoom disabled via the viewport meta tag the zoom shouldn't be changing. To make things even stranger: IF I REFRESH THE PAGE OR EVEN NAVIGATE TO SOME OTHER WEBSITE THE ZOOM WILL NOT REFRESH.
I've also noticed this occuring on other websites. I've tried every conceivable meta tag combination (that disables zooming). I'm testing with an iPad 3. If I only have one tab open in Safari I have no issues.
This doesn't seem to be related to the "famous" orientation issue as the undesirable zoom occurs when the application does not have focus
How do I reset the scale/zoom of a web app on an orientation change on the iPhone?

Here is how I fixed this:
1. use the onorientationchange event to detect if the zoom is changed
2. if the zoom has changed change the viewport meta tag to: user-scalable=yes
3. on $(window).resize or onorientationchange change viewport back to user-scalable=no if the user has changed the zoom back to fit the screen

Related

How to handle Safari iOS zoom on input fields

My responsive web app (made with Angular Material) works fine except with input fields on iOS / Safari: when the user focuses on an input field, iOS zooms the web page. Then the zoom level remains, breaking the responsiveness of the app (because then, the viewport becomes scrollable, and for instance the toolbar is no longer sticked to the top. Also, some elements supposed to be always visible on the left and on the right, are outside of the visible area due to the zoom).
I have followed recommendations given here and there, for instance https://www.warrenchandler.com/2019/04/02/stop-iphones-from-zooming-in-on-form-fields/ and iOS Safari zoom on input box.
An almost working approach consists to use the following in the HTML header:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0"/>
However this is not good enough in my case:
setting user-scalable=0 prevents the user to zoom the view
setting maximum-scale=1 also prevents the user to zoom on Chrome/Android (even if user-scalable=yes)
the trick with the "load" event (given in the 2nd link) does not work (I suspect because this is not called when changing page in a single-page application like Angular)
the trick using font-size=16px does not work for me (like many people also report).
Would anyone have a suggestion, to:
either prevent the focus on an input field to cause a zoom
or resetting the zoom to 1 after this operation
while letting users zoom the view manually if they wish to
?
Are any of your font sizes smaller than 16px?
You might be experiencing a browser behavior that isn't related to Angular Material.
My team experienced a similar problem. We found your question as part of our work. We eventually realized that the viewport zooming behavior that we saw had nothing to do with Angular Material. That's simply what iOS does when the font on an input field is less than 16px: https://css-tricks.com/16px-or-larger-text-prevents-ios-form-zoom/ Any input field. Angular Material has nothing to do with it.
Related: Please note that disabling viewport zoom for mobile was standard practice for about a decade after the introduction of the iPhone, but it is no longer The Way. https://webkit.org/blog/7367/new-interaction-behaviors-in-ios-10/

Scaling issue on orientation change with keyboard on for a web page on iOS

To fix the auto scaling issues to render my webpage on an iOS device, I've added the viewport meta tag,
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum- scale=1,user-scalable=no">
and I've added device specific styling through media queries for iPhone and iPad, This fixed the scaling issues on switching between portrait/landscape orientations.
The problem now is that when I shift focus to an input field(bringing the keyboard up) and shifting to landscape orientation with the keyboard on(auto scaling happens fine) and when I switch orientation back to portrait mode(with the keyboard still on), the UI gets distorted, i.e., some extra length gets added to the viewport width which either appears as black area or part of the same viewport being repeated again. And if I bring down the keyboard and switch orientations again, the added space gets removed and the UI gets back to normal again. This happens only with the keyboard on. I'm using mobile safari as my browser.
I've been working with Mobile Safari for years now, and one thing I've learned -- it's so buggy when it comes to orientation changes when an input has focus.
Saying that, here's a small script that might help you out.
window.addEventListener('orientationchange', function(){
document.body.style.paddingRight = '1px';
setTimeout(function(){
document.body.style.paddingRight = '';
}, 50);
}, true);
This basically forces the browser to reflow/re-calculate the layout, which should hopefully address the situation you're seeing.
Fiddle with an easy to reproduce bug: https://jsfiddle.net/LYn54
Fiddle with the fix: https://jsfiddle.net/gQR4m
Hope this helps!

iPad - Zooms in on orientation change while focused on input field

This is similar issue with Focus on input field and orientation change messes up zoom level on iOS 6 Safari but link is for App, and not the site.
I have following meta tag (please note that zooming is purposely disabled - not my call, client's request :D)
<meta name="viewport" id="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0">
With zooming disabled and max-scale set to 1.0, orientation change works fine when you are just browsing the site. However, when you focus on input and change orientation, it starts to add some weird stuff on page.
When changing from:
portrait to landscape - iPad adds some black block at bottom of the page.
landscape to portrait - width of page gets wider. I inspected the element using mac and that whatever the space added is outside of html and shows up even with overflow: hidden; on both html and body tag.
Same issue happens on sign-in page of google - orientation change works perfectly fine when not focused on input fields, but when you focus on either email or password field and change orientation, iPad zooms in for some reason (you have to focus from portrait then once keyboard is visible, change orientation to landscape, it zooms in).
Luckily for Google, user is able to zoom-in and out but for me there's requirement from client that zooms has to be disabled.
Anyone have any workaround about this issue?
Thanks in advance!
I have found that this issue appears when page height is not set or set to 100%. I just set min height for page container.

Mobile Safari Web App Zoom issue

I am building a mobile web app that uses jQuery and hammer.js for touch controls. hammer.js has a feature called "prevent_default" which turns off Safari's scrolling/zooming/prettymucheverything. I have a page with a form using < input > for text fields, and a javascript listener that calls .focus() when you tap the form.
This all works well up until a point. The page is fixed in place and looks real pretty, and when you click on a form field it zooms in and the iOS keyboard appears. The problem is that when the user is done entering text, there is no way to zoom out. The browser is so zoomed in from .focus() that the browser bar is gone and you have to close the browser tab and re-type in the URL instead of refreshing.
I am looking for a way to force the browser to zoom out back to the initial view. I've looked all over the internet for some solution but have yet to find anything.
I have the viewport meta tags in the header to disable zooming from the beginning, but is not useful in solving this issue
A hacky solution is to focus and blur an inputfield after you have changed the viewport attributes.
function refreshViewportZoom(){
var viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'initial-scale=0.5, maximum-scale=0.5, scale=0.5, user-zoom=0.5, zoom=0.5');
document.getElementById('myInputField').focus();
setTimeout(blurLater,2000);
}
function blurLater(){
document.getElementById('myInputField').blur();
}
The blurLater is needed as a function, because Safari seems to look ahead and ignore it otherwise.

Make a website automatically load in Landscape view on an iPad

I'm wondering if anyone can help me. I have created a website and I want it to automatically load in landscape view on the iPad. Is this possible and if so can it be done with javascript or css?
You can't change the frame (the Safari window, status bar, URL bar, etc) from inside JavaScript / HTML, but you could wrap your whole site in a div and add the "-webkit-transform: rotate(90deg);" attribute when you detect that it's in portrait orientation.
That will display your site in landscape, but the user will probably then rotate the device itself into landscape which would then rotate your content incorrectly oriented relative to the user. You'd have to detect that using JS and remove the CSS attribute above when you truly are in landscape. If you're using jQuery or something I could imagine it being relatively easy, but the user may still see a bit of flickering as the content bounces around.

Resources