raklos raklos - 3 months ago 10
Javascript Question

Get relative path of the page url using javascript

In javascript, how can I get the relative path of the current url?

for example

http://www.example.com/test/this?page=2


I want just the
/test/this?page=2

Answer

Try

window.location.pathname+window.location.search