Javascript to get the size and location of the window code sharing, javascript window

Source: Internet
Author: User

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 );
})();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.