bom 指浏览器对象模型,可以通过js 操作浏览器。
window -整个浏览器窗口 也是网页的全局对象
navigator -浏览器信息
location -浏览器地址栏信息,可以获取地址或者操作
history -浏览器的历史记录 该对象不能获取到具体的历史记录, 只能操作浏览器向前 或者 向后。
screen - 获取用户当前使用的显示器屏幕的相关信息
navigator 可以获得浏览器的信息, navigator.useragent 可以获得当前是什么浏览器, 拿到的是字符串 可以通过正则来判断是谷歌还是火狐等, 但是ie11判断不出来,但ie可以通过 ie特有的属性activexobject来判断。 var useragent = navigator.useragent; if (/firefox/i.test(useragent)) { alert("你是火狐"); } else if (/chrome/i.test(useragent)) { alert("你是chrome"); } else if("activexobject" in window){ alert("你是ie"); }
history 历史记录
history.forward() 像前跳, history.back()向后跳, history.go(参数),history.go(1)相当于 history.forward(); var next=document.getelementbyid("next"); var prev=document.getelementbyid("prev"); next.onclick=function(){ // history.forward(); history.go(1); } prev.addeventlistener("click",function(){ // history.back(); history.go(2); },false)
loaction 可以获得当前地址栏信息, 跳转地址, 刷新地址等。当前地址:
loction.href.跳转:
1.location=“http://www.baidu.com”;
2. location.assign(“http://www.baidu.com”);
3.location.replace(“http://www.baidu.com”); //替换, 不能回退刷新:
location.reload(true); // 加上true 强制清空表单, 不加只刷新页面不清空表单。
以上就是javascript中bom的介绍(代码示例)的详细内容。
