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

Location origin attribute

JavaScript Location  Object

originThe read-only property returns the protocol, hostname, and port number of a URL.

Note:If the port number is not specified in the URL, the origin property will not return the port number.

Syntax:

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

Browser compatibility

All browsers fully support the origin property:

property
originisisisisis

Technical details

Return value:A string representing the protocol (including://),domain name or IP address and port number, including the colon (:) of the URL. For usefileThe URL scheme, the value depends on the browser.

More examples

This example displays all location attributes:

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.host property

Location Reference:location.hostname property

Location Reference:location.pathname property

Location Reference:location.protocol property

JavaScript Location  Object