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:

“http://www.demo.com/Sports/Running/Shoes?item=1&size=10&color=green”

To get the full url use:

first_full

To only get the origin use:

second

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.

thrid

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

fourth