經常使用的BOM Api:html
// 純HTML內容區域的寬高(不包括收藏夾,導航欄等) window.innerHeight; window.innerWidth;
// 包含收藏夾、導航欄、邊框等元素的視窗寬高 window.outerHeight; window.outerWidth;
// 與瀏覽器無關,只跟屏幕有關的(固定的)寬高 screen.height; screen.width;
// 與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'
// 與瀏覽器相關的信息 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