<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取URL信息</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.info-box {
background-color: #f5f5f5;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.url-item {
margin-bottom: 10px;
}
.url-label {
font-weight: bold;
display: inline-block;
width: 100px;
}
</style>
</head>
<body>
<h1>当前页面URL信息</h1>
<div class="info-box">
<div class="url-item">
<span class="url-label">完整URL:</span>
<span id="full-url"></span>
</div>
<div class="url-item">
<span class="url-label">域名:</span>
<span id="domain"></span>
</div>
<div class="url-item">
<span class="url-label">相对路径:</span>
<span id="pathname"></span>
</div>
</div>
<script>
// 获取当前页面的URL信息
document.addEventListener('DOMContentLoaded', function() {
const currentUrl = window.location.href;
const domain = window.location.hostname;
const pathname = window.location.pathname;
document.getElementById('full-url').textContent = currentUrl;
document.getElementById('domain').textContent = domain;
document.getElementById('pathname').textContent = pathname;
});
</script>
</body>
</html>

被折叠的 条评论
为什么被折叠?



