JS浏览器对象-Location对象

时间:2023-03-09 16:52:46
JS浏览器对象-Location对象

JS浏览器对象-Location对象

1、返回web主机的域名

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body> <button id="btn" onclick="getLoc()">按钮</button>
<p id="ptime"></p>
<script>
function getLoc(){
//返回web主机的域名
document.getElementById("ptime").innerHTML = window.location.hostname;
}
</script> </body>
</html>

2、返回web主机的域名

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body> <button id="btn" onclick="getLoc()">按钮</button>
<p id="ptime"></p>
<script>
function getLoc(){
//返回web主机的域名
document.getElementById("ptime").innerHTML = window.location.pathname;
}
</script> </body>
</html>

其他方式类似。