You can get the URL or parts for it using the window.location object.
For example, consider the following URL:
These are the standard properties of the window.location object and the value you will get for the above URL:
property | value -----------+----------------------------------------------------- hash |
For example, if you want to check the path name, you can do the following:
if (window.location.pathname === '/search') { // do something }
Daniel Vassallo
source share