什么是BOM
- 浏览器对象模型
- BOM使我们可以通过JS操作浏览器
- 在BOM中为我们提供了一组对象来完成对浏览器的操作
- window
代表整个浏览器窗口,同时也是网页中的全局对象
- navigator
代表当前浏览器信息,通过该对象可以识别不同的浏览器
- location
代表当前浏览器地址栏信息,可以获取地址栏信息或者操作浏览器跳转
- history
代表浏览器历史记录,可以通过该对象来操作浏览器历史记录,由于隐私原因,该对象不能获取到具体历史记录,只能操作本次访问向前向后翻页
- screen
代表用户的屏幕信息,通过该对象可以获取到用户的显示器相关信息
- 可以通过window对象使用,也可以直接使用
Navigator
var ua = navigator.userAgent
if(/firefox/i.test(ua)){
alert('火狐')
}else if(/chrome/i.test(ua)){
alert('chrome')
}else if(/msie/i.test(ua)){
alert('ie')
}else if('ActiveXObject' in window){
alert('ie11')
}
History
alert(history.length)
history.back()
history.forward()
history.go(-1)
Location
alert(location)
location = 'http://www.baidu.com/'
loacation = './1.html'
location.assign('http://www.baidu.com/')
location.replace('http://www.baidu.com/')
location.reload(true)
定时器
var count = document.getElementById('div')
var num = 1
clearInterval(timer)
var timer = setInterval(function(){
count.innerHTML = num++
if(num == 11){
clearInterval(timer)
}
},1000)
var timer1 = setInterval(function(){
}
},1000)
clearInterval(timer1)