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
If you want the country domain name - for example to extract .com from stackoverflow.com :
(ES6):
const getCountryDomainName = () => {
let hostName = window.location.hostname;
let lastDotIndex = hostName.lastIndexOf('.');
let countryDomainName = hostName.substr(lastDotIndex+1, hostName.length);
return countryDomainName;
}
(ES5):
function getCountryDomainName() {
let hostName = window.location.hostname;
let lastDotIndex = hostName.lastIndexOf('.');
let countryDomainName = hostName.substr(lastDotIndex+1, hostName.length);
return countryDomainName;
}
Then, just use the function to assign the value to a var:
const countryDomainName = getCountryDomainName();