iOS9 Safari viewport issues, meta not scaling properly?

半城伤御伤魂 提交于 2019-12-11 10:19:09

问题


I have a bizarre issue with a recent website deployment - the website is not scaling properly on any iOS9 Safari-mobile browser which appears to shrink the site.

This does not appear to be a problem for any other device as far as I can see and I have tested it on Firefox (Android and Desktop), Chrome (Android and Desktop), Safari (Desktop), IE (Desktop).

Does anyone know a fix for this?

Many thanks

[UPDATE]

Following on from a discussion here this meta seems to do the job:

<meta name="viewport" content="initial-scale=1.0001, minimum-scale=1.0001, maximum-scale=1.0001, user-scalable=no"/>

Only issue is, I don't wish to change the viewport like this in case it effects other devices. Is there a better fix specifically for iOS9? Perhaps via browser sniffing?

Thanks again


回答1:


I ended up using HTTP_USER_AGENT and use a different meta for each condition (PHP solution below):

<?php 
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'],'iPad' ) || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod' ) !== false){
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'OS 9') !== false) {
        echo '<meta name="viewport" content="initial-scale=1.0001, minimum-scale=1.0001, maximum-scale=1.0001, user-scalable=no"/>';
    }
    else {
        echo '<meta name="viewport" content="<WHATEVER_CONTENT>"/>';
    }
} else {
    echo '<meta name="viewport" content="<WHATEVER_CONTENT>"/>';
}?>

Hope this helps anyone else who has this issue in the future.

[UPDATE - Better approach below]

Better yet, rather than the browser sniffing approach, thanks to Krepelk (following on from the original forum mentioned earlier) - Since iOS9 they introduced a "Shrink to fit" feature for webpages with content stretching further than the viewport.

This can be reverted by adding shrink-to-fit=no in the viewport meta tag:

<meta name="viewport" content="width=device-width, initial-scale=1, min-scale=1, max-scale=1, shrink-to-fit=no">

And voila! Problem is resolved and reverted back to the iOS8 functionality. I imagine this will affect many websites...



来源:https://stackoverflow.com/questions/33618595/ios9-safari-viewport-issues-meta-not-scaling-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!