Latest web development tutorials

Location hostname property

Location Object Reference Location Object

Definition and Usage

hostname property is a readable and writable string sets or returns the current URL's hostname.

grammar

location.hostname


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support hostname property


Examples

Examples

Returns the host name of the current URL:

<script>

document.write(location.hostname);

</script>

Examples of the above output:


try it"


Location Object Reference Location Object