We can find out the domain name from URL by using location.hostname property.
var mydomain=window.location.hostname;
or we can also use location.href property but it’s a little harder.
var mydomain=window.location.href.match(/:\/\/(.[^/]+)/)[1];
The hostname property can be set to redirect location, but it is safer to set the href property.