Location 对象的属性
属性 | 描述 | IE | F | O |
---|
hash | 设置或返回从井号 (#) 开始的 URL(锚)。 | 4 | 1 | 9 |
host | 设置或返回主机名和当前 URL 的端口号。 | 4 | 1 | 9 |
hostname | 设置或返回当前 URL 的主机名。 | 4 | 1 | 9 |
href | 设置或返回完整的 URL。 | 4 | 1 | 9 |
pathname | 设置或返回当前 URL 的路径部分。 | 4 | 1 | 9 |
port | 设置或返回当前 URL 的端口号。 | 4 | 1 | 9 |
protocol | 设置或返回当前 URL 的协议。 | 4 | 1 | 9 |
search | 设置或返回从问号 (?) 开始的 URL(查询部分)。 | 4 | 1 | 9 |
Location 对象的方法
方法 | 描述 | IE | F | O |
---|
assign() | 加载新的文档。 | 4 | 1 | 9 |
reload() | 重新加载当前文档。 | 4 | 1 | 9 |
replace() | 用新的文档替换当前文档。 | 4 | 1 | 9 |
示例代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>Title</title>
</head>
<body>
<input type="button" value="通过location来实现链接到一个新页面" onclick="location.href='Demo11.html'"/>
</body>
</html>