示例:获取当前 URL
// program to get the URL
const url1 = window.location.href;
const url2 = document.URL;
console.log(url1);
console.log(url2);
输出
https://www.google.com/ https://www.google.com/
在上面的程序中,使用了 window.location.href 属性和 document.URL 属性来获取当前页面的 URL。
window.location.href 和 document.URL 属性都会返回当前页面的 URL。