Location.host

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

location.host

Description

The host property of the Location object represents the host portion of the URL. This is composed of the hostname and the port number (if available).

In the following fictitious Web address:

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

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

Example

Listing 7.381 shows the how the host property is used.

Listing 7.381 Example of the host Property
<html>
<head>
<title> Using the hash property of the Location object</title>
</head>
<body>

<script language="JavaScript">
<!--Hide

// shows the host part of the URL
function show(){
     document.form1.text1.value=document.location.host
}
							 // End ...

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.