Get the current URL with JavaScript?

后端 未结 23 2010
梦谈多话
梦谈多话 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条回答
  •  走了就别回头了
    2020-11-21 07:47

    The way to get the current location object is window.location.

    Compare this to document.location, which originally only returned the current URL as a string. Probably to avoid confusion, document.location was replaced with document.URL.

    And, all modern browsers map document.location to window.location.

    In reality, for cross-browser safety, you should use window.location rather than document.location.

提交回复
热议问题