1

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
  • 1
    What is your question exactly?
    – Pekka
    Jan 13 '11 at 11:29
3

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.