url = window.location.hostname; // get host name like http://www.baidu.com
var res = url.split('.'); // split by dot
var top_level_domain = res[res.length - 1]; // get last element in array
console.log(top_level_domain); // com
url = window.location.hostname; // get host name like http://www.baidu.com
var res = url.split('.'); // split by dot
var top_level_domain = res[res.length - 1]; // get last element in array
console.log(top_level_domain); // com
转载于:https://www.cnblogs.com/lzbrest/p/7028645.html