共计 1008 个字符,预计需要花费 3 分钟才能阅读完成。
常用的 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
正文完