English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Location protocol attribute

JavaScript Location Object

protocolSets or returns the protocol of the current URL, including the colon ( : ).

Syntax:

Return protocol attribute:

location.protocol

Set protocol attribute:

location.protocol = protocol
var x = location.protocol;
document.querySelector("#output").innerHTML = x;
Test and See‹/›

Browser compatibility

All browsers fully support the protocol attribute:

Attribute
protocolIsIsIsIsIs

Attribute value

ValueDescription
protocolA string that specifies the protocol of the URL
Possible values:
  • http:

  • https:

  • file:

  • FTP:

  • mailto:

  • More...

Technical details

Return value:A string representing the protocol of the current URL, including the colon ( : )

More examples

This example displays all location properties:

var txt = "";
txt += "<p>Host: " + location.host + "</p>";
txt += "<p>Hostname: " + location.hostname + "</p>";
txt += "<p>Href: " + location.href + "</p>";
txt += "<p>Origin: " + location.origin + "</p>";
txt += "<p>Pathname: " + location.pathname + "</p>";
txt += "<p>Protocol: " + location.protocol + "</p>";
txt += "<p>Search: " + location.search + "</p>";
document.write(txt);
Test and See‹/›

Related References

Location Reference:location.href property

Location Reference:location.host property

Location Reference:location.origin property

JavaScript Location Object