X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Location host Property

Location Object Reference Location Object

Example

Return the hostname and port of the current URL:

var x = location.host;

The result of x will be:


Try it yourself »


Definition and Usage

The host property sets or returns the hostname and port of a URL.

Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will not display the port number.


Browser Support

Property
host Yes Yes Yes Yes Yes


Syntax

Return the host property:

location.host

Set the host property:

location.host=hostname:port

Parameter Values

Value Type Description
hostname:port String Specifies the hostname and port number of the URL

Technical Details

Return Value: A String, representing the domain name and port number, or the IP address of a URL


Location Object Reference Location Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook