Firstly, lets look at a very simple example below:
<input type="button" value="Click Here" onclick="alert(window.location.href);">
And now lets look at it in action:
Hopefully, when you click the button above you should see a popup alert containing the website address. This should match the URL in your browsers address bar.
Easy huh? But that’s not all…
As you’ll know there are multiple parts to a website address (the query string, the filename, the domain name etc). Above we used the ‘href’ property to get the full website address, but what if you only want a certain part of the URL? Luckily there are a few different properties we can use to get the bit we need. A full list of these properties can be found at the following URL: