Get the current URL with JavaScript?

后端 未结 23 2002
梦谈多话
梦谈多话 2020-11-21 07:08

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 va

23条回答
  •  梦毁少年i
    2020-11-21 08:03

    To get the path, you can use:

    console.log('document.location', document.location.href);
    console.log('location.pathname',  window.location.pathname); // Returns path only
    console.log('location.href', window.location.href); // Returns full URL

提交回复
热议问题