// location (地址栏对象信息)
//http://127.0.0.1:5500/04.location.html
console.log(window.location);
//host:域名和端口号
console.log(window.location.host);
//hostname:域名
console.log(window.location.hostname);
//href:完整的url地址
//给值就是设置不给值就是获取
console.log(window.location.href);
// 网页跳转
// window.location.href = "https://www.baidu.com";
// port 端口号
console.log(window.location.port); //5500
//protocol 协议
console.log(window.location.protocol); //http:
//pathname 路径地址
console.log(window.location.pathname); ///04.location.html
// http://127.0.0.1:5500/04.location.html?name=%E5%93%88%E5%93%88&age=100#heihie
//hash 哈希值 #..
console.log(window.location.hash); //#heihie
//search 获取通过?传递参数
console.log(window.location.search); //?name=%E5%93%88%E5%93%88&age=100
window.location用法
最新推荐文章于 2024-06-25 16:21:19 发布
本文详细介绍了JavaScript中window.location对象的各个属性及其使用方法,包括如何获取和设置URL的不同部分,如主机名、端口、路径、搜索参数等。
1139

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



