更新时间:2023-02-25 15:09:21
你可以这样做:
location.hostname.split('.').pop()
编辑
看到您的问题的更改,您需要一份所有TLD列表要匹配和删除主机名,那么你可以使用 split('。')。pop()
Saw the change to your question, you would need a list of all TLDs to match against and remove from the hostname, then you could use split('.').pop()
// small example list
var re = new RegExp('\.+(co.uk|me|com|us)')
var secondLevelDomain = 'https://www.google.co.uk'.replace(re, '').split('.').pop()