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

Location hostname Property

Location Object Reference Location Object

Example

Return the hostname of the current URL:

var x = location.hostname;

The result of x will be:


Try it yourself »


Definition and Usage

The hostname property sets or returns the hostname of a URL.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The hostname property is supported in all major browsers.


Syntax

Return the hostname property:

location.hostname

Set the hostname property:

location.hostname=hostname

Value Type Description
hostname String Specifies the hostname of the URL

Return Value

Type Description
String The domain name, 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 BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook