Get relative path of the page url using javascript

后端 未结 7 1155
温柔的废话
温柔的废话 2020-12-29 19:48

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 /te

7条回答
  •  [愿得一人]
    2020-12-29 20:45

    You should use it the javascript way, to retrieve the complete path including the extensions from the page,

    $(location).attr('href'); 
    

    So, a path like this, can be retrieved too.

    www.google.com/results#tab=2  
    

提交回复
热议问题