Meta viewport tag seems to be ignored completely or has no effect

后端 未结 7 1741
不思量自难忘°
不思量自难忘° 2021-02-07 19:09

I have put this tag in the head of a webpage:

For s

相关标签:
7条回答
  • 2021-02-07 19:44

    It seems that ios7 is not recognising the meta tag properly. Here are the links which may help you.

    webapp not scaling properly in iOS 7

    http://www.mobilexweb.com/blog/safari-ios7-html5-problems-apis-review

    0 讨论(0)
  • 2021-02-07 19:47

    Viewport width is different in may devices. iOS has 320, android has 360 in portrait mode. Landscape mode - it depends on which device you have, you will get different different width.

    Best way to make website optimized for mobile is set width=device-width. If you don't set initial-scale=1.0 - iOs will zoom in (enlarge) screen when changing device rotation.

    This meta is all you needed.

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    And if you wanted to disable the zoom feature, set user-scalable=no

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    

    Do not hard code width property as it will set same width for portrait and landscape modes - which is very unpleasing user experience.

    Best documented: https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

    About iOs 7 Moreover I would say - dont worry about iOS7 as of now. It has so many bugs. Read here: http://www.sencha.com/blog/the-html5-scorecard-the-good-the-bad-and-the-ugly-in-ios7/

    0 讨论(0)
  • 2021-02-07 19:50

    I know this is a hella old question now but it was the first result in Google when I had this issue so thought I'd update in regards to iOS 10.

    It seems Apple now completely overrides the user-scalable=no in iOS 10 in order to improve accessibility

    See: Thomas Fuchs' Twitter Post

    0 讨论(0)
  • 2021-02-07 19:51

    It is working! On your page you are using:

    <meta content="width=640, initial-scale=0.47, maximum-scale=1.0, user-scalable=1" name="viewport">
    

    When I open the page on my phone (ios7 iphone5) I see exactly the right result.

    Are you 100% sure you really tried putting the following in your code?

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    

    It doesn't get ignored.

    UPDATE1

    I just saw that in your code it seems you are using my second viewport but i gets changed probably by javascript to the 640px viewport. Thats maybe the reason why for you it feels like it gets ignored. Because during runtime the viewport gets changed...

    UPDATE2

    Ok found the problem.

    function updateWidth(){
        viewport = document.querySelector("meta[name=viewport]");
        if (window.orientation == 90 || window.orientation == -90) {
            viewport.setAttribute('content', 'width=1401, initial-scale=0.34, maximum-scale=1.0, user-scalable=1');
        }
        else {
            viewport.setAttribute('content', 'width=640, initial-scale=0.47, maximum-scale=1.0, user-scalable=1');
        }
    } 
    

    Your page is calling this function which overrides your viewport. Did you know about that function?

    0 讨论(0)
  • 2021-02-07 19:53

    You shouldn't be worrying about IOS 7 yet, it has so many bugs: http://www.infoworld.com/t/html5/bad-news-ios-7s-html5-full-of-bugs-227685

    May be your code is perfectly okay but issue with iOS?

    0 讨论(0)
  • 2021-02-07 19:55

    Use below code.

    <meta name="viewport" content="width=320, initial-scale=1, user-scalable=yes">
    

    It works well in many of mine project.

    0 讨论(0)
提交回复
热议问题