1 window.onload = function() {
2 alert("width: " + getPageScale().pageWidth + ", height: " + getPageScale().pageHeight);
3 };
4
5 /**
6 * 获取浏览器视口大小
7 * @return {object} 宽,高
8 */
9 function getPageScale(){
10 var pageWidth = window.innerWidth,
11 pageHeight = window.innerHeight;
12
13 if (typeof pageWidth !== "number") {
14 if (document.compatMode === "CSS1Compat") {
15 pageWidth = document.documentElement.clientWidth;
16 pageHeight = document.documentElement.clientHeight;
17 }else{
18 pageWidth = document.body.clientWidth;
19 pageHeight = document.body.clientHeight;
20 }
21 }
22
23 return {pageWidth, pageHeight};
24 }