示例: 获取当前 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。