console.log(window.location.origin);//页面的来源
console.log(window.location.hostname);//获取主机名
console.log(window.location.port);//端口号
console.log(window.location.protocol);//协议
console.log(window.location.pathname);//根目录下的路径
console.log(window.location.href);//返回完整的url
console.log(window.location.hash);//返回从#开始的锚点
console.log(window.location.search);//返回?后面的信息
前端路线--H5篇 获取路径
最新推荐文章于 2025-03-08 20:47:52 发布
这篇博客详细介绍了JavaScript中window.location对象的使用,包括获取页面来源、主机名、端口号、协议、路径、完整URL、锚点和查询参数的方法。通过这些属性,开发者可以更好地理解和操作网页URL。
1万+

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



