Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

get subdomain of url

Hi,

I wish to grab the subdomain portion of a url using javascript. I have this client's url:
http://medicaid-florida.medicaidconsultants.com/

I want to grab only the portion 'medicaid-florida' and save it to a variable.

Is there an easy way to do this?

Thank you,
vkimura
ASKER CERTIFIED SOLUTION
Avatar of Samuel Liew
Samuel Liew
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of halfbloodprince
halfbloodprince

THIS WORKS!!!!:
function getSubDomain()
        {
            var str = "http://medicaid-florida.medicaidconsultants.com/"
            var arrValue = str.split("//");
            var arrSecondValue = arrValue[1].split(".");
            var result = arrSecondValue[0];
            alert(result);

        }
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

Hi govindarajan78,

What's the difference between the two?
the location.host will omit the file names & querystrings if any