Javascript to get the size and location of the window code sharing, javascript window
In Javascript, you can use OuterWidth and OuterHeight to obtain the browser size. Use innerWidth and innerHeight to obtain the window size (excluding the browser border ). For IE6 and earlier versions, the standard mode or hybrid mode should be distinguished. The standard mode uses document.documentelement.clientwidth,document.doc umentElement. clientHeight. The clientWidth and clientHeight of document. body are used in the hybrid mode.
Copy codeThe Code is as follows:
(Function (){
Var pageWidth = window. innerWidth;
Var pageHeight = window. innerHeight;
Var broswerWidth = window. outerWidth;
Var broswerHeight = window. outerHeight;
Alert (pageWidth + "" + pageHeight );
Alert (broswerWidth + "" + broswerHeight );
If (typeof pageWidth! = "Number "){
If (document. compatMode = "CSS1Compat") {// The standard mode
PageWidth = document.doc umentElement. clientWidth;
PageHeight = document.doc umentElement. clientHeight;
} Else {
PageWidth = document. body. clientWidth;
PageHeight = document. body. clientHeight;
}
}
})();
Obtain the position of the window: IE, chrome, Safari, use screenLeft, screenTop to obtain the position of the window from the left and top of the screen. Firefox does not support this attribute. Firefox uses screenXP and screenY to achieve the same effect.
Copy codeThe Code is as follows:
(Function btnFun (){
Var leftPos = (typeof window. screenLeft = "number ")? Window. screenLeft:
Window. screenX;
Var topPos = (typeof window. screenTop = "number ")? Window. screenTop:
Window. screenY;
Alert (leftPos + "" + topPos );
// Alert (window. screenLeft + "" + window. screenTop );
})();