[JavaScript] Javascript 获取页面的大小尺寸 →→→→→进入此内容的聊天室

来自 , 2021-03-20, 写在 JavaScript, 查看 107 次.
URL http://www.code666.cn/view/676b5876
  1. //
  2. // getPageSize()
  3. // Returns array with page width, height and window width, height
  4. // Core code from - quirksmode.org
  5. // Edit for Firefox by pHaez
  6. //
  7. function getPageSize(){
  8.        
  9.         var xScroll, yScroll;
  10.        
  11.         if (window.innerHeight && window.scrollMaxY) { 
  12.                 xScroll = document.body.scrollWidth;
  13.                 yScroll = window.innerHeight + window.scrollMaxY;
  14.         } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  15.                 xScroll = document.body.scrollWidth;
  16.                 yScroll = document.body.scrollHeight;
  17.         } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  18.                 xScroll = document.body.offsetWidth;
  19.                 yScroll = document.body.offsetHeight;
  20.         }
  21.        
  22.         var windowWidth, windowHeight;
  23.         if (self.innerHeight) { // all except Explorer
  24.                 windowWidth = self.innerWidth;
  25.                 windowHeight = self.innerHeight;
  26.         } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  27.                 windowWidth = document.documentElement.clientWidth;
  28.                 windowHeight = document.documentElement.clientHeight;
  29.         } else if (document.body) { // other Explorers
  30.                 windowWidth = document.body.clientWidth;
  31.                 windowHeight = document.body.clientHeight;
  32.         }      
  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.  
  41.         // for small pages with total width less then width of the viewport
  42.         if(xScroll < windowWidth){     
  43.                 pageWidth = windowWidth;
  44.         } else {
  45.                 pageWidth = xScroll;
  46.         }
  47.  
  48.  
  49.         arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  50.         return arrayPageSize;
  51. }
  52. //javascript/2042

回复 "Javascript 获取页面的大小尺寸"

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

captcha