BOM自带方法/window扩展方法
window.location.href = "地址" (可以让页面跳转到指定的地址)
window.location.reload() (清空刷新页面)
window.history.forward() (实现页面的前进<切换页面>)
window.history.go(1) 页面切换 : 1表示前进一次 2即为前进2次 -1为后退一次
window.history.back() 页面的后退<切换页面>
window.open("网址") //可以打开外部网址
window.close() // 只能关闭原页面,
- window.navigator 用户代理信息
在h5中需要检测用户是用移动端还是pc端打开页面,根据不同的内核要显 示移动或pc端网页
window.navigator.userAgent;
//5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
- window.screen
window.screen.height
和浏览器有关系的距离
document.documentElement.clientHeight//浏览器现在可视化的页面高度
document.documentElement.scrollHeight//浏览器本身的高度,固定值,不会随着浏览器的放大缩小而改变
document.documentElement.scrollTop //浏览器滚动条滚动了多少距离 - setInterval
var num = 10;
var timer = setInterval(function () {
alert(num);
num--;
if (num == -1) {
clearInterval(timer); //停止倒计时
}
},1000); //每隔一秒输出一次
//延时器 2s后输出
var timer = setTimeout(function () {
alert("hha");
clearTimeout(timer); //清楚定时器
}, 2000);