Location hostnameProperty

Location 对象参考手册Location Object

Definition and Usage

The hostname property is a readable and writable string that can set or return the hostname of the current URL.

Syntax

location.hostname


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the hostname property


Examples

Examples

Return the hostname of the current URL:

<script>

document.write(location.hostname);

</script>

The output of the above example is:


Try it yourself »


Location 对象参考手册Location Object Other Extensions