location
介绍
location
对象既是 window
的属性,也是 document
的属性,即:
window.location
document.location
它们是一样的,打印值如下:
JS
{
"href": "http://localhost:8080/js/bom/location.html", //
"origin": "http://localhost:8080", // 源
"protocol": "http:", // 协议
"host": "localhost:8080", // 主机
"hostname": "localhost", // 域名
"port": "8080", // 端口号
"pathname": "/js/bom/location.html",
"search": "", // ? 后的值
"hash": "" // hash 值
}
{
"href": "http://localhost:8080/js/bom/location.html", //
"origin": "http://localhost:8080", // 源
"protocol": "http:", // 协议
"host": "localhost:8080", // 主机
"hostname": "localhost", // 域名
"port": "8080", // 端口号
"pathname": "/js/bom/location.html",
"search": "", // ? 后的值
"hash": "" // hash 值
}
方法
window.location.assign(url)
等价于window.location = url
window.location.replace(url)
window.location.reload(true)