Tag Archives: url

Javascript

Javascript quick tip – returning urls

A few quick Javascript tips for you.  If you want to return or store the value of the current url of your page, try this:-

window.location.href

This will give you the entire url that is displayed in the address bar.

 

If you have a url containing a hash value (ie http://www.2toria.com/index.php#section1) and want to return the hash, then use this:-

window.location.hash

 

Want just the top-level domain name (eg www.2toria.com)?  Give this a whirl:-

window.location.hostname