JavaScript code instance: JS Get browser width

Source: Internet
Author: User
Tags array return window

Article Introduction: JS Gets the browser window wide and the width of the page is high.

JS access to the browser window width and width of the page height:

/**
/Third FUNCTION
* GetPageSize () by webjx.com
*
* @return Array return a array with page width, height and window width, height
*/
function ___getpagesize () {
var xscroll, Yscroll;
if (window.innerheight && window.scrollmaxy) {
Xscroll = window.innerwidth + Window.scrollmaxx;
Yscroll = Window.innerheight + window.scrollmaxy;
else if (Document.body.scrollHeight > Document.body.offsetHeight) {//all but Explorer Mac
Xscroll = Document.body.scrollWidth;
Yscroll = Document.body.scrollHeight;
else {//Explorer mac...would also work in Explorer 6 Strict, Mozilla and Safari
Xscroll = Document.body.offsetWidth;
Yscroll = Document.body.offsetHeight;
}
var windowwidth, WindowHeight;
if (self.innerheight) {//all except Explorer
if (document.documentElement.clientWidth) {
WindowWidth = Document.documentElement.clientWidth;
} else {
WindowWidth = Self.innerwidth;
}
WindowHeight = Self.innerheight;
else if (document.documentelement && document.documentElement.clientHeight) {//Explorer 6 Strict Mode
WindowWidth = Document.documentElement.clientWidth;
WindowHeight = Document.documentElement.clientHeight;
else if (document.body) {//other explorers
WindowWidth = Document.body.clientWidth;
WindowHeight = Document.body.clientHeight;
}
For small pages and total height less then height of the viewport
if (Yscroll < WindowHeight) {
PageHeight = WindowHeight;
} else {
PageHeight = Yscroll;
}
For small pages and total width less then width of the viewport
if (Xscroll < windowwidth) {
PageWidth = Xscroll;
} else {
PageWidth = WindowWidth;
}
Arraypagesize = new Array (pagewidth,pageheight,windowwidth,windowheight);
return arraypagesize;
};



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.