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