URL Through JavaScript

JavaScript by default gives you full access to the browser’s url property through the global window.location object.  Let’s use this following url as an example:


To get the full url use:


To only get the origin use:


With these two properties you can extract any values that you want using regular string functions, such as:

If you don’t care about the origin use the following.


If you would like to remove the query string values as well use this