2

常用的BOM Api:

  • window
  • screen
  • location
  • navigator
  • document
  • history(已弃用)
window、screen
// 纯HTML内容区域的宽高(不包括收藏夹,导航栏等)
window.innerHeight; 
window.innerWidth; 
// 包含收藏夹、导航栏、边框等元素的视窗宽高
window.outerHeight; 
window.outerWidth; 
// 与浏览器无关,只跟屏幕有关的(固定的)宽高
screen.height; 
screen.width; 
location
// 与URL相关的信息
/*
http://www.example.com:8080/path/index.html?a=1&b=2#TOP
*/

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'
navigator
// 与浏览器相关的信息
console.log('appName = ' + navigator.appName);
console.log('appVersion = ' + navigator.appVersion);
console.log('language = ' + navigator.language);
console.log('platform = ' + navigator.platform);
console.log('userAgent = ' + navigator.userAgent);

// appName = Netscape
// appVersion = 5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
// language = zh-CN
// platform = Win32
// userAgent = Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36

時雨
91 声望6 粉丝

慢慢地把云笔记上的内容搬过来~