Web APIs

Window.location

Try the free JavaScript compiler

Exposes the active document URL through Location. Reading it is not navigation; assign and replace have navigation effects.

Formal Syntax & Structure

javascript syntaxjavascript
window.location.href

Return Value

string

Current document URL when href is read.

Working Example

Example Snippetjavascript
(async () => {const before=location.href;const u=new URL("https://example.test/a");u.pathname="/b";console.log(location.href===before,u.pathname);})()
JavaScript Reference