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

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

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

For s

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 19:51

    It is working! On your page you are using:

    
    

    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?

    
    

    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?

提交回复
热议问题