This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

window.location.protocol

Summary

Sets or retrieves the protocol portion of a URL. The protocol the current document was accessed via (everything preceding the “//”).

Property of apis/locationapis/location

Syntax

Note: This property is read-only.

var result = window.location.protocol;

Return Value

Returns an object of type StringString

The protocol the current document was accessed via.

For example, http://example.org/ would return the protocol http:.

Examples

The following example assumes your document has a div element with id 'hostDiv’, like this.

// Get the protocol from window.location
var hostpr = window.location.protocol;

// Get a div element with id 'hostDiv'
var container = document.getElementById('hostDiv');

// Fill in the div element with the host protocol
container.innerHTML = hostpr;

Related specifications

Window Object 1.0
W3C Working Draft
URL
W3C Working Draft