How to get the URL without any parameters in JavaScript?

前端 未结 9 1492
终归单人心
终归单人心 2020-12-04 09:12

If I use:

alert(window.location.href);

I get everything including query strings. Is there a way to just get the main url part, for example:

9条回答
  •  长情又很酷
    2020-12-04 09:45

    If you look at the documentation you can take just the properties you're interested in from the window object i.e.

    protocol + '//' + hostname + pathname
    

提交回复
热议问题