前端获取当前页面链接
在前端中,可以使用 window.location.href 来获取当前页面链接。这个属性返回当前页面的完整URL(包括协议、主机名、路径和查询字符串)。例如:
const currentUrl = window.location.href;
console.log(currentUrl);
输出结果可能是:
https://www.example.com/path/to/page.html?foo=bar#section1
其中, https://www.example.com 是协议和主机名部分, /path/to/page.html 是路径部分, ?foo=bar 是查询字符串部分, #section1 是锚点部分。
原文地址: https://www.cveoy.top/t/topic/hakH 著作权归作者所有。请勿转载和采集!