Javascript Get Website URL

后端 未结 7 2032
别那么骄傲
别那么骄傲 2020-12-29 05:37

How do I get Javascript to tell me the website url.

For example if I have a page www.example.com/page.html

I want Javascript to tell me the site

7条回答
  •  余生分开走
    2020-12-29 06:17

    There are many ways to get this.
    Open Chrome browser and press F12, you'll get console.

    Type following commands there for the same question URL. You will get your answer

    window.location.hostname // Output : stackoverflow.com
    
    window.location.origin // Output : http://stackoverflow.com
    
    document.location.host // Output : stackoverflow.com
    

提交回复
热议问题