The window.location object is used to obtain the url attribute in the web page.
Properties of windows.location object
Attributes | describe |
letter | Returns the entire url of the current page |
protocol | What is returned is the protocol of the url |
hostname | What is returned is the host name (domain name) |
host | What is returned is the host name (domain name) including the port number. |
port | Returns the host port |
pathname | Returns the pathname of the current page |
search | What is returned? The following part (contains?) |
hash | Return to anchor point (starting from #) |
Click the a tag to jump to other.html with parameters
<body>
<a href="./other.html?id=1">跳转</a>
</body>
Accept parameters in a tag in other.html
<body>
<script>
// 用=将路由参数分割成数组
let idArray = window.location.search.split('=');
console.log(idArray);//[?id,1]
// 获取路由的参数
let assetId = idArray[1];
console.log(assetId);//1
</script>
</body>