![446103cc85827aba8c3fa9a019d0665e.png](https://i-blog.csdnimg.cn/blog_migrate/bed626c12325d243990de34592cbc8aa.png)
BOM部分基础内容
BOM(Broswer Object Model)浏览器对象模型 ,主要用来获取或设置浏览器的属性、行为 ; 使JavaScript可以和浏览器进行交互 ; window 是 BOM 对象,而非 js 对象 ;
注:凡是window的属性和方法,均可以省略“window.”
- 【1】常见框窗操作
1.警告框
window.alert("msg");
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="application/javascript">
//
//警告框
function testAlert(){
var result = alert("这是一个警告框!");
console.log(result);
}
</script>
</head>
<body>
<button onclick="testAlert();">testAlert</button>
</body>
</html>
2.确认框
window.confirm("msg");
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="application/javascript">
//确认框
function testConfirm(){
var result = confirm("你确认要离开了吗?");
if(result){
alert("欢迎下次再来!")
}else{
alert("那你在逛逛吧!")
}
console.log(result);
}
</script>
</head>
<body>
<button onclick="testConfirm();">testConfirm</button>
</body>
</html>
3.询问框
window.prompt("msg","defaulvalue")
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="application/javascript">
//询问框
function testPrompt(){
var result = window.prompt("请输入U盾密码","例如:123456");
console.log(result);
}
</script>
</head>
<body>
<button onclick="testPrompt();">testPrompt</button>
</body>
</html>
- 【2】常见页面操作
1.打开一个窗口
window.open()
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="application/javascript">
var a = 10;
window.onload = function(){
console.log(window);
console.log("11111111111")
}
function testOpen(){
var sonwindow = window.open("son.html","aaa","height=300,width=500,top=50,left=50,toolbar=no,
menubar=no,scrollbars=no,resizable=no,location=no,status=no")
//子窗口的window对象
console.log(sonwindow);
}
function fatherSayHello(){
alert("hello son!");
}
</script>
</head>
<body>
<button onclick="testOpen();">打开一个新窗口</button>
</body>
</html>
2.在子窗口中使用,表示父窗口的window对象
window.opener
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="