Js_javascript tips for getting the page, window height and width accurately
Source: Internet
Author: User
function GetPageSize () {
var xscroll, Yscroll;
if (window.innerheight && window.scrollmaxy) {
Xscroll = Document.body.scrollWidth;
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
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 = WindowWidth;
} else {
PageWidth = Xscroll;
}
Arraypagesize = new Array (pagewidth,pageheight,windowwidth,windowheight)
return arraypagesize;
}
Fortunate enough to find your this dongdong, help me solve the problem, but looked carefully, as if there is a big problem, parameter value and name on the look like a bit on the number OH.
For small pages and total height less then height of the viewport
if (Yscroll < WindowHeight) {
PageHeight = Yscroll;
} else {
PageHeight = WindowHeight;
}
For small pages and total width less then width of the viewport
if (Xscroll < windowwidth) {
PageWidth = Xscroll;
} else {
PageWidth = WindowWidth;
}
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