Get The Current Domain Name With Javascript (Not the path, etc.)

前端 未结 17 2216
情歌与酒
情歌与酒 2020-12-04 05:43

I plan on buying two domain names for the same site. Depending on which domain is used I plan on providing slightly different data on the page. Is there a way for me to de

17条回答
  •  独厮守ぢ
    2020-12-04 06:12

    Try to run in script : path: http://localhost:4200/landing?query=1#2

    console.log(window.location.hash)
    

    Location have following values:

    window.location.hash: "#2"
    ​
    window.location.host: "localhost:4200"
    ​
    window.location.hostname: "localhost"
    ​
    window.location.href: "http://localhost:4200/landing?query=1#2"
    ​
    window.location.origin: "http://localhost:4200"
    ​
    window.location.pathname: "/landing"
    ​
    window.location.port: "4200"
    ​
    window.location.protocol: "http:"
    
    window.location.search: "?query=1"
    

提交回复
热议问题