JavaScript implementation gets window size and location code sharing _javascript Tips

Source: Internet
Author: User

You can use Outerwidth,outerheight to get the size of the browser in JavaScript. Use Innerwidth,innerheight to get the size of the window (except for the browser's border portion). For IE6 and previous versions, distinguish between standard mode and promiscuous mode. Standard mode uses document.documentelement.clientwidth,document.documentelement.clientheight promiscuous mode to use Document.body of Clientwidth,clientheight.

Copy Code code 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.documentElement.clientWidth;
PageHeight = Document.documentElement.clientHeight;
} else {
PageWidth = Document.body.clientWidth;
PageHeight = Document.body.clientHeight;
}
}
})();

Get the position of the window: Ie,chrome,safari, use screenleft,screentop to get the window's position from the left side of the screen and the top of the screen. Firefox does not support this property, Firefox uses Screenxp,screeny to achieve the same effect.

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

Related Article

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.