JavaScript document.location usage

Explaining the Usage of JavaScript document.location

This article explains the usage of JavaScript's document.location.

Shou Arisaka
1 min read
Nov 12, 2025

Explaining the usage of JavaScript’s document.location.

document.location allows you to get the current page’s URL or change the URL.

Using the origin method saves you the trouble of URL regex replacement.

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:"

Share this article

Shou Arisaka Nov 12, 2025

🔗 Copy Links