使用 window.location.href 可取得目前頁面的完整網址。
document.write(window.location.href);
可用來記錄來源頁、產生分享連結、判斷目前頁面,或與其他參數組合。
location.href 包含協定、網域、路徑與查詢字串。若只需要部分資訊,可搭配 location.pathname、location.search 或 location.hash。