42 lines
1.0 KiB
HTML
42 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript">
|
|
// location对象(即是对象也是window的属性)
|
|
console.log(location)
|
|
console.log(window.location)
|
|
// url中#和#后的内容
|
|
console.log(location.hash)
|
|
//主机和端口号
|
|
console.log(location.host)
|
|
//主机名
|
|
console.log(location.hastname)
|
|
//文件路径-------相对文件
|
|
console.log(location.pathname)
|
|
//端口
|
|
console.log(location.port)
|
|
//协议
|
|
console.log(location.protocol)
|
|
//?和后面的内容(参数)
|
|
console.log(location.search)
|
|
window.onload = function(){
|
|
document.getElementById('btn').onclick = function(){
|
|
//alert(111)
|
|
//跳转(属性)
|
|
// location.href = 'https://www.baidu.com'
|
|
//跳转(方法)
|
|
// location.assign('https://www.jd.com')
|
|
//刷新
|
|
location.reload()
|
|
//无历史记录跳转
|
|
location.replace('https://www.baidu.com')
|
|
}
|
|
}
|
|
</script>
|
|
<input type="button" name="" value="跳转" id="btn">
|
|
</body>
|
|
</html> |