faqts : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 23 people (87%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I find the host part of the url?
How can I find the host part of the url?

Apr 7th, 2000 09:50
Martin Honnen,


The
  location
object (which is a property of the window object so complete path is
  window.location
) has two properties
  host
and
  hostname
where host is the hostname plus port number so for instance with 
location.href being
  http://JavaScript.FAQTs.com:80
the property
  location.hostname
is
  JavaScript.FAQTs.com
while
  location.host
is
  JavaScript.FAQTs.com:80
If you want the protocol part use
  location.protocol
which is
  http:
in the above example. Thus you can reconstruct the complete host part 
of the with 
  location.protocol + '//' + location.host