Javascript - how to remove domain from location.href

前端 未结 4 565
遥遥无期
遥遥无期 2021-02-06 22:00

I need to remove the domain name from location.href using Javascript. I have links like: http://localhost/App/User/UserOrder.aspx?id=949abc91-a644-4a02-aebf-96da3ac7d8e1&a

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 22:37

    Use window.location.pathname. This gives you the path relative to the host. See here for more details.

    For any arbitrary URL, assuming that the variable url contains your URL, you can do:

    url = url.replace(/^.*\/\/[^\/]+/, '')
    

提交回复
热议问题