Location.hostname

JavaScript 1.0+, JScript 1.0+ Nav2+, IE 3+, Opera3+ Syntax

location.hostname

Description

The hostname property of the Location object represents the hostname portion of the URL.

In the following fictitious Web address:

http://www.mcp.com:80/foo?something#foobar

the hostname value would be the http://www.mcp.com portion.

Example

Listing 7.382 shows an example of how the hostname property is used. When the button is clicked, the show() function is called, which displays the value of hostname in the text box.

Listing 7.382 Example of the hostname Property
<html>
<head>
<title> Using the hostname property of the Location object</title>
</head>
<body>

<script language="JavaScript">
<!-- Hide
							 // displays the hostname ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.