iOS return bad value for window.innerHeight/Width

前端 未结 8 2046
悲哀的现实
悲哀的现实 2020-12-15 16:13

I\'m using window.innerHeight and window.innerWidth instructions to get the browser\'s available window size. It\'s working with firefox, safari (on a mac

8条回答
  •  借酒劲吻你
    2020-12-15 16:27

    Was stuck on the same issue. Here's the solution that worked for me.

    First I'm detecting if the client is an iOS device. Then i'm getting correct values using Screen interface

    var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; 
    var iw = (iOS) ? screen.width : window.innerWidth, ih = (iOS) ? screen.height : window.innerHeight;
    

提交回复
热议问题