Location 对象
Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。
Location | 对象的属性 |
---|---|
属性 | 描述 |
hash | 设置或返回从井号 (#) 开始的 URL(锚)。 |
host | 设置或返回主机名和当前 URL 的端口号。 |
hostname | 设置或返回当前 URL 的主机名。 |
href | 设置或返回完整的 URL。 |
pathname | 设置或返回当前 URL 的路径部分。 |
port | 设置或返回当前 URL 的端口号。 |
protocol | 设置或返回当前 URL 的协议。 |
search | 设置或返回从问号 (?) 开始的 URL(查询部分)。 |
Location 对象的方法
方法 | 描述 |
---|---|
assign() | 加载新的文档。 |
reload() | 重新加载当前文档。 |
replace() | 用新的文档替换当前文档。 |
例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> loaction </title>
<meta charset="utf-8" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<script type="text/javascript">
<!--
function func(){
window.location.href = "http://www.baidu.com";
}
function func1(){
window.location.reload;
}
//-->
</script>
<body >
<input type="button" value="进入百度" onclick="func()" />
<input type="button" value="刷新页面" onclick="func1()" />
</body>
</html>
以上内容作为个人学习记录,仅供参考。