[JavaScript] js获取浏览器窗口宽高及网页宽高 →→→→→进入此内容的聊天室

来自 , 2021-02-10, 写在 JavaScript, 查看 139 次.
URL http://www.code666.cn/view/c1d53b7a
  1. /**
  2.  / THIRD FUNCTION
  3.  * getPageSize() by quirksmode.com
  4.  *
  5.  * @return Array Return an array with page width, height and window width, height
  6.  */
  7. function ___getPageSize() {
  8.         var xScroll, yScroll;
  9.         if (window.innerHeight && window.scrollMaxY) { 
  10.                 xScroll = window.innerWidth + window.scrollMaxX;
  11.                 yScroll = window.innerHeight + window.scrollMaxY;
  12.         } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  13.                 xScroll = document.body.scrollWidth;
  14.                 yScroll = document.body.scrollHeight;
  15.         } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  16.                 xScroll = document.body.offsetWidth;
  17.                 yScroll = document.body.offsetHeight;
  18.         }
  19.         var windowWidth, windowHeight;
  20.         if (self.innerHeight) { // all except Explorer
  21.                 if(document.documentElement.clientWidth){
  22.                         windowWidth = document.documentElement.clientWidth;
  23.                 } else {
  24.                         windowWidth = self.innerWidth;
  25.                 }
  26.                 windowHeight = self.innerHeight;
  27.         } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  28.                 windowWidth = document.documentElement.clientWidth;
  29.                 windowHeight = document.documentElement.clientHeight;
  30.         } else if (document.body) { // other Explorers
  31.                 windowWidth = document.body.clientWidth;
  32.                 windowHeight = document.body.clientHeight;
  33.         }      
  34.         // for small pages with total height less then height of the viewport
  35.         if(yScroll < windowHeight){
  36.                 pageHeight = windowHeight;
  37.         } else {
  38.                 pageHeight = yScroll;
  39.         }
  40.         // for small pages with total width less then width of the viewport
  41.         if(xScroll < windowWidth){     
  42.                 pageWidth = xScroll;           
  43.         } else {
  44.                 pageWidth = windowWidth;
  45.         }
  46.         arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
  47.         return arrayPageSize;
  48. };
  49. //javascript/4651

回复 "js获取浏览器窗口宽高及网页宽高"

这儿你可以回复上面这条便签

captcha