2

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? Commented Jan 13, 2011 at 11:29

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.