BOM 浏览器对象模型
BOM (浏览器对象模型),它提供了与浏览器窗口进行交互的对象前端
1、window对象web
Window对 象表示整个浏览器窗口。
1.系统消息框 alert()浏览器
alert('hello world!');
2.确认对话框 confirm() 函数
该方法返回一个boolean值,若是点击ok返回true,点击cancel返false;工具
if(confirm("肯定要删除吗?")){ //删除 }
3.输入对话框 prompt()ui
若是点击ok将文本框中的值做为函数值返回,若是点击cancel返回nullspa
//若是用户不输入任何值或点击取消,那么脚本会一直弹出对话框
function requiredPrompt() { while(true) { var name = prompt("ssss"); if(name != null && name != "") { console.log(name); break; } } }
4. 打开新窗口 window.open()操作系统
window.open("http://www.baidu.com","_blank","width=300, height=200");
5.定时器setInterva() 、 setTimeout() code
定时器能够说是js前端最经常使用的工具,几乎全部的逐渐变化的动态效果都会使用到定时器,好比 说图片滚动,渐隐渐现,拖拽等等.定时器分两种分别是settimeout和setinterval. 对象
window.setInterval(); //设置循环定时器 var T = window.setInterval(test,1000); // test:执行的代码串或函数 设置1000毫秒 window.clearInterval(); //清除循环定时器 window.clearInterval(T); window.setTimeout(); //设置单次定时器 var T = setTimeout(test,1000); // test:执行的代码串或函数 设置1000毫秒 window.clearTimeout() // 清除单次定时器 clearTimeout();
2、history对象
history对象是window对象的子对象,对应于浏览器的 历史记录。
window.history.go(-1);//跳转前一个页面 window.history.go(1);//跳转下一个页面 history.back();//跳转前一个页面 history.forward();//跳转下一个页面
3、Location对象
Location对象也是window对象的子对象,经过它能够获取或设置浏览器的当前地址。
1.跳转到其它页面
window.location.href = "http://www.163.com";
location.href = "http://www.163.com";
2.从新载入页面(刷新)
location.reload();
4、navigator对象
Navigator对象包含着有关web浏览器的信息,它也是window的属性,能够用 window.navigator 引用它,也能够用navigator引用
例:获取浏览器内部代号,名称,操做系统等信息
var info = navigator.userAgent; alert(info);
效果图以下