screen.width/screen.height not updating after screen rotation

后端 未结 4 1575
野趣味
野趣味 2021-02-13 02:58

I\'m experiencing this problem on an iPhone device (iPhone 7, iOS 10, but also other iPhones too): in javascript, if I intercept the orientationchange event, inside the handler,

4条回答
  •  庸人自扰
    2021-02-13 03:26

    iOS used to return the size of the screen as if it was in portrait. They changed it on iOS 8 (on the native classes), but they might have forgotten to do it for Safari, or maybe they kept it that way for compatibility.

    If you want the real size based on the orientation you can use window.innerWidth and window.innerHeight

    I get the same values with or without the viewport meta tag

    It works fine on Chrome simulated visualization because it return the screen size of the simulated visualization, as it should be, but it doesn't simulate the OS where it should be running based on the device, so you won't get the same values as on a real device (in this case in which the real device doesn't return good values)

提交回复
热议问题