How Do I Get innerWidth in Internet explorer 8

前端 未结 8 1101
一整个雨季
一整个雨季 2020-12-08 00:06

In all recent browser:

 window.innerWidth // 1920

In Internet explorer 8

 window.innerWidth // undefined

8条回答
  •  死守一世寂寞
    2020-12-08 00:49

    Without jQuery you can try this to get height and width

    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') { //Chrome
         myWidth = window.innerWidth; 
         myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
         myWidth = document.documentElement.clientWidth; 
         myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE9
         myWidth = document.body.clientWidth; 
         myHeight = document.body.clientHeight;
    }
    

提交回复
热议问题