Get the current URL with JavaScript?

2018-12-31 01:53发布

All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please.

20条回答
明月照影归
2楼-- · 2018-12-31 02:44

Open Developer Tools, type in the following in the console and press Enter.

window.location

Ex: Below is the screenshot of the result on the current page.

enter image description here

Grab what you need from here. :)

查看更多
弹指情弦暗扣
3楼-- · 2018-12-31 02:44

Use: window.location.href.

As noted above, document.URL doesn't update when updating window.location. See MDN.

查看更多
登录 后发表回答