JavaScript document.location 使い方

JavaScriptのdocument.locationの使い方を解説

この記事では、JavaScriptのdocument.locationの使い方を解説しています。

Shou Arisaka
1 分で読める
2017年7月4日

JavaScriptのdocument.locationの使い方を解説します。

document.locationは、現在のページのURLを取得したり、URLを変更したりすることができます。

originメソッドを使えばurl正規表現置換の手間も省ける。

document.location.href
"https://tpc.googlesyndication.com/safeframe/1-0-9/html/container.html"
document.location.origin
"https://tpc.googlesyndication.com"
document.location.pathname
"/safeframe/1-0-9/html/container.html"
document.location.host
"tpc.googlesyndication.com"
document.location.protocol
"https:"

この記事をシェア

Shou Arisaka 2017年7月4日

🔗 リンクをコピー