I need to extract a sub domain and pass to a variable to then add into a url so that a link will work on a number of different environments
1 Answer
var sub_domain = window.location.split('.')[0].split('//')[1];
This should do the trick. this line of code will get current url, then will split it using "." as a separator, then will take first part. and then get rid of "http://". so if current url is "http://maps.google.com/" script will return "maps". However if there is no subdomain it will return domain instead.