634 _BOM_Window_属性 and 635 BOM_Location
3. 属性:
1. 获取其他BOM对象:
history
location
Navigator
Screen:
2.获取DOM对象
document
4. 特点
Window对象不需要创建可以直接使用 window使用。 window.方法名();
window引用可以省略。 方法名();
<script>
/*
// 获取history
var h1 = window.history;
// 省略版
var h2 = history;
// 弹窗显示
alert(h1);
// 弹窗显示
alert(h2);*/
//获取对象
var openBtn = window.document.getElementById("openBtn");
// 弹窗显示
alert(openBtn);
</script>
Location:地址栏对象
1. 创建(获取):
1. window.location
2. location
2. 方法:
reload() 重新加载当前文档。刷新
3. 属性
href 设置或返回完整的 URL。
<body>
<!--定义一个刷新的一个按钮-->
<input id="t1" type="button" value="刷新">
<!--定义一个跳转网址的一个按钮-->
<input id="t2" type="button" value="百度">
<script>
//reload方法,定义一个按钮,点击按钮,刷新当前页面
//获取按钮对象
var t1 = document.getElementById("t1");
//绑定单击事件
t1.onclick = function () {
//刷新页面
location.reload();
}
//获取href
var href = location.href;
//弹窗显示
//alert(href);
//点击按钮跳转网址
//获取按钮
let t2 = document.getElementById("t2");
//绑定事件
t2.onclick = function () {
//要跳转的官网
location.href = "https://www.baidu.com";
}
</script>

浙公网安备 33010602011771号