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

前端 未结 17 2215
情歌与酒
情歌与酒 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:10

    If you are not interested in the host name (for example www.beta.example.com) but in the domain name (for example example.com), this works for valid host names:

    function getDomainName(hostName)
    {
        return hostName.substring(hostName.lastIndexOf(".", hostName.lastIndexOf(".") - 1) + 1);
    }
    

提交回复
热议问题