Request address in JavaScript

Javascript

Javascript Problem Overview


> Possible Duplicate:
> Get current URL with JavaScript?

How do you get the address of the page you are on in JavaScript?

For example, if I had a script at somesite.com/javascript/home.html and I want to find out the request address (somesite.com/javascript/home.html), how do I get this information in JavaScript?

Javascript Solutions


Solution 1 - Javascript

You need to use: document.location or window.location

You can read more here. Or there is a little more explanation over there.

For clarifying matter:

Originally Posted by Mozilla Developer Center

> document.location was originally a > read-only property, although Gecko > browsers allow you to assign to it as > well. For cross-browser safety, use > window.location instead.

Solution 2 - Javascript

window.location.href;

or

location.href; 

window is the global object, so location.href will be identical to window.location.href and NOT document.location.href (as long as there's no enclosing function or with statement which shadows the property)

Solution 3 - Javascript

What you are looking for is window.location.href.

Solution 4 - Javascript

I believe that either the window.location.href or the window.location.pathname objects will have this information.Someone could confirm or deny that though.

Solution 5 - Javascript

document.URL

Solution 6 - Javascript

document.location.href

or

window.location.href

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLB.View Question on Stackoverflow
Solution 1 - JavascriptArtem BargerView Answer on Stackoverflow
Solution 2 - JavascriptJoelView Answer on Stackoverflow
Solution 3 - JavascriptdreadwailView Answer on Stackoverflow
Solution 4 - JavascriptAdam LermanView Answer on Stackoverflow
Solution 5 - JavascriptDaniel MouraView Answer on Stackoverflow
Solution 6 - JavascriptTalhaView Answer on Stackoverflow