Get domain name without subdomains using JavaScript?

后端 未结 8 1559
陌清茗
陌清茗 2020-11-29 06:48

How to get the domain name without subdomains?

e.g. if the url is \"http://one.two.roothost.co.uk/page.html\" how to get \"roothost.co.uk\"?

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 07:10

    You can try this in JavaScript:

    alert(window.location.hostname);
    

    It will return the hostname.

提交回复
热议问题