开发工具与关键技术:Adobe Dreamweaver JavaScript
作者:执~漠
撰写时间:2020年4月27日
1.浏览器对象模型BOM是宿主元素
2. navigator
navigator对象表示浏览器的信息,最常用的属性包括:
navigator.appName:浏览器名称;
navigator.appVersion:浏览器版本;
navigator.language:浏览器设置的语言;
navigator.platform:操作系统类型;
navigator.userAgent:浏览器设定的User-Agent字符串。
例如:console.log(navigator.appName);// 浏览器名称
console.log(navigator.appVersion);// 浏览器版本
console.log(navigator.language);// 浏览器设置的语言
console.log(navigator.platform);// 操作系统类型
console.log(navigator.userAgent);// 浏览器设定的User-Agent字符串
2.window对象
innerWidth和innerHeight属性,可以获取浏览器窗口内部宽度和高度。内部宽度是指除去菜单栏,工具栏,边框等占位元素后,用于显示页面的净宽高。
例: window.innerWidth//浏览器内容宽度
window.innerHeight//浏览器内容高度
outerWidth和outHeight属性,可以获取浏览器窗口的整个宽高
例:window.outerWidth;//浏览器窗口的整个宽度
window.outerHeight;//浏览器窗口的整个高度
window.open()打开新窗口
window.close()关闭当前窗口
window.moveTo()移动当前窗口
window.resizeTo()重新调整当前窗口
window.location.href 返回当前页面的 href (URL)
window.location.hostname 返回 web 主机的域名
window.location.pathname 返回当前页面的路径或文件名
window.location.protocol 返回使用的 web 协议(http: 或 https:或file:)
window.location.assign 加载新文档
例:console.log(window.location.href);
console.log(window.location.hostname);
console.log(window.location.pathname);
console.log(window.location.protocol);
console.log(window.location.assign);
3.screen对象表示屏幕的信息,常用的属性有:
screen.width 属性返回以像素计的访问者屏幕宽度
screen.height 属性返回以像素计的访问者屏幕的高度
screen.colorDepth 返回颜色位数,如8,16,24
screen.availWidth属性返回访问者屏幕的宽度,以像素计,减去诸如窗口工具条之类的界面特征
screen.availHeight属性返回访问者屏幕的高度,以像素计,减去诸如窗口工具条之类的界面特征
screen.pixelDepth属性返回屏幕的像素深度
例:console.log(screen.width);// 屏幕宽度
console.log(screen.height);// 屏幕高度
console.log(screen.colorDepth);// 颜色位数
console.log(screen.availWidth);
console.log(screen.availHeight);
console.log(screen.pixelDepth);