Android browser's screen.width, screen.height & window.innerWidth & window.innerHeight are unreliable

后端 未结 8 1504
一个人的身影
一个人的身影 2020-12-05 02:53

I\'m working on a web app that is targeted to browsers on desktop, tablet and smartphone.

The web app has a light box implemented using Colorbox with an iframe

相关标签:
8条回答
  • 2020-12-05 03:16

    I took me hours to find a workaround.

    The only constant among window.innerHeight, window.outerheight, etc was screen.height.

    This code gave me the outerheight:

    screen.height / window.devicePixelRatio - window.screenTop
    

    Also, in order to support older versions of android, place your code in a setTimeout

    I hope this is helpful =)

    0 讨论(0)
  • 2020-12-05 03:23

    On Android, window.outerWidth and window.outerHeight are reliably the screen size. Depending on your version of Android, innerWidth/Height is usually incorrect.

    Here's a really good writeup on the situation.

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