<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BOM</title>
</head>
<script>
window.onload=function (){
var oBtn=document.getElementsByTagName('input')[0];
var oBtn1=document.getElementsByTagName('input')[1];
var opener=null;
/*
open() 方法 open方法是window对象下的一个方法,但是在js中前面可以省略window
open(url) url为空:默认打开空白页面
close() 方法 关闭窗口 有兼容性问题,不同浏览器处理方式不一样
*/
/*
oBtn.onclick=function (){
opener=window.open();
alert(opener==window);//false open方法的返回值是新打开窗口的window对象
opener.document.body.style.backgroundColor='red';
}*/
/*
//关闭当前窗口
oBtn.onclick=function (){
close();
}
*/
/* //关闭新窗口
oBtn1.onclick=function (){
opener.close();
}
*/
/* //浏览器信息属性
oBtn.onclick=function (){
alert(window.navigator.userAgent);
}
*/
/* oBtn.onclick=function (){
/*
Location 对象包含有关当前 URL 的信息
Location 对象是Window对象的一个属性,可通过window.location的方式来访问
*/
alert(window.location);//设置或返回完整的URL
alert(window.location.href);//设置或返回完整的URL
alert(window.location.search);//设置或返回从?开始的URL查询部分
alert(window.location.hash);//设置或返回从#开始的URL锚
}
}
</script>
</head>
<body>
<input type="button" name="btn" value="打开窗口">
<input type="button" name="btn" value="关闭窗口">
</body>
</html>