BOM 浏览器对象模型 BOM由多个对象组成,其中代表浏览器窗口的Window对象是BOM的顶层对象,其他对象都是该对象的子对象。 DOM与BOM的区别
BOM是Browser Object Model的缩写,即浏览器对象模型。BOM没有相关标准。不同浏览器定义有差别,实现方式不同。BOM的最根本对象是window。 DOMDOM是Document Object Model的缩写,即文档对象模型。DOM是W3C的标准。DOM最根本对象是document(实际上是window.document)。 DOM的最根本的对象是BOM的window对象的子对象。 BOM是浏览器对象模型,DOM是文档对象模型,前者是对浏览器本身进行操作,而后者是对浏览器(可看成容器)内的内容进行操作Location对象 打开窗口 open(“http://www.163.com”,"_blank",“width=200,height=200,left=300,top=100”)
document.οnclick=function(){ close();//关闭窗口 }
console.log(innerWidth,innerHeight);//视口宽高 console.log(outerWidth,outerHeight);//窗口宽高
窗口距离屏幕左上角的位置 console.log(screenLeft,screenTop); console.log(screenX,screenY);
location.reload();//重载
location.href=“http://www.163.com”;//设置可以跳转页面 location.assign(“http://www.163.com”);//设置跳转页面 location.replace(“http://www.163.com”);//设置跳转页面,替换 交互时不同,replace没有历史记录
console.log(location.hash);//获取当且页面中的锚标记#后面的内容 console.log(location.search);//获取地址栏中?后面的内容 console.log(location.hostname)// 返回 web 主机的域名
history对象 history history.back();//向后回退 history.forward();//向前 history.go(0);//刷新页面 history.go(1);//向前 history.go(-1);//回退 history.length 历史数量 history.pushState(); history.replaceState(); window.onpopstate
screen对象 availHeight屏幕的高度像素减去系统部件高度之后的值 availWidth屏幕的宽度像素减去系统部件宽度后的值 height屏幕的高度像素 width屏幕的宽度像素
navigator对象 console.log(navigator.appCodeName); console.log(navigator.appName);// 返回浏览器的名称。 console.log(navigator.appVersion);//返回浏览器的平台和版本信息。 console.log(navigator.clipboard); console.log(navigator.geolocation);//经纬度 console.log(navigator.platform);// 返回运行浏览器的操作系统平台。 console.log(navigator.userAgent);// 返回由客户机发送服务器的 user-agent 头部的值