Location hostProperty

Location 对象参考手册Location Object

Definition and Usage

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

Syntax

location.host


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the host property


Example

Example

Return the hostname and port of the current URL:

<script>

document.write(location.host);

</script>

The output of the above example is:


Try it yourself »


Location 对象参考手册Location Object Other Extensions