1 client: function() { 2 if(window.innerWidth !== null){ // 最新的浏览器 3 return { 4 "width": window.innerWidth, 5 "height": window.innerHeight 6 } 7 }else if(document.compatMode === 'CSS1Compat'){ // W3C 8 return { 9 "width": document.documentElement.clientWidth, 10 "height": document.documentElement.clientHeight 11 } 12 } 13 return { 14 "width": document.body.clientWidth, 15 "height": document.body.clientHeight 16 } 17 }
1 console.log(window.innerWidth, window.innerHeight); 2 console.log(document.documentElement.clientWidth, document.documentElement.clientHeight); 3 console.log(document.body.clientWidth, document.body.clientHeight);