HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptCritical

Get the current URL with JavaScript?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
withurlthecurrentjavascriptget

Problem

All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please.

Solution

Use:
window.location.href


As noted in the comments, the line below works, but breaks if you have a frame, image, or form with name="URL".
document.URL


See URL of type DOMString, readonly.

Context

Stack Overflow Q#1034621, score: 4592

Revisions (0)

No revisions yet.