引言:如何通过javascript获取当前html页面的链接信息
let currentUrl = window.location.href;
let protocol = window.location.protocol; // 协议
let host = window.location.host; // 主机名和端口
let hostname = window.location.hostname; // 主机名
let port = window.location.port; // 端口
let pathname = window.location.pathname; // 路径
let search = window.location.search; // 查询字符串
let hash = window.location.hash; // 锚点
let base_url = protocol + "//" + host + "/";
console.log('currentUrl:' +currentUrl);
console.log("Protocol: " + protocol);
console.log("Host: " + host);
console.log("Hostname: " + hostname);
console.log("Port: " + port);
console.log("Pathname: " + pathname);
console.log("Search: " + search);
console.log("Hash: " + hash);
console.log('base_url == ' + base_url);
运行结果如下: