tags:

views:

10985

answers:

4

This seems like a rather simple request but no amount of Googling has turned up a satisfactory answer, which is surprising because all I want is to get the website URL. Not the URL as taken from a link (I can already do that just fine) 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.

Can anyone help me?

+13  A: 

Gets the current page URL:

window.location.href
Zanoni
Note that that’s the window’s location not the document’s.
Gumbo
It's the same thing.Full current URL refers to the document path (external address).
Zanoni
Is it standardized like document.url? (I mean something like a w3c document)
chendral
@chendral: http://www.w3.org/TR/Window/#location
Christoph
+19  A: 

alert( document.URL );
see http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-46183437

VolkerK
+11  A: 

The same question has been asked less than 24 hours ago. To quote myself:

Use window.location for read and write access to the location object associated with the current frame. If you just want to get the address as a read-only string, you may use document.URL, which should contain the same value as window.location.href.

Christoph
see also http://stackoverflow.com/questions/2430936/whats-the-difference-between-window-location-and-document-location-in-javascript/2431375#2431375
Christoph
A: 

window.location.href

nozukakung