File size: 1,004 Bytes
08aee07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Location对象</title>
</head>
<body>
<input type="button" id="btn" value="刷新">
<input type="button" id="goBaidu" value="去百度">
<script>
/*
Location:地址栏对象
1. 创建(获取):
1. window.location
2. location
2. 方法:
* reload() 重新加载当前文档。刷新
3. 属性
* href 设置或返回完整的 URL。
*/
//reload方法,定义一个按钮,点击按钮,刷新当前页面
var btn = document.getElementById("btn");
btn.onclick = function() {
location.reload();
}
//获取href
var href = location.href;
alert("href=" + href);
var btn2 = document.getElementById("goBaidu");
btn2.onclick = function() {
location.href="http://www.baidu.com";
}
</script>
</body>
</html> |