JavaScript で画面、ウィンドウ、Web ページのサイズを取得する

1. 画面サイズを取得する

// 获取屏幕宽度
var screenWidth = window.screen.width;

// 获取屏幕高度
var screenHeight = window.screen.height;

// 获取屏幕可用工作区宽度(不包括任务栏等)
var screenAvailableWidth = window.screen.availWidth;

// 获取屏幕可用工作区高度(不包括任务栏等)
var screenAvailableHeight = window.screen.availHeight;

2. ウィンドウサイズを取得する

// 获取窗口宽度
var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

// 获取窗口高度
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

3. Web ページのサイズを取得する

// 获取整个网页的宽度(包括滚动条)
var pageWidth = Math.max(
  document.body.scrollWidth,
  document.documentElement.scrollWidth,
  document.body.offsetWidth,
  document.documentElement.offsetWidth,
  document.documentElement.clientWidth
);

// 获取整个网页的高度(包括滚动条)
var pageHeight = Math.max(
  document.body.scrollHeight,
  document.documentElement.scrollHeight,
  document.body.offsetHeight,
  document.documentElement.offsetHeight,
  document.documentElement.clientHeight
);

// 获取网页可见区域的宽度
var pageVisibleWidth = document.documentElement.clientWidth;

// 获取网页可见区域的高度
var pageVisibleHeight = document.documentElement.clientHeight;

おすすめ

転載: blog.csdn.net/qq_31851435/article/details/132887733