English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
location.origin
var x = location.origin; document.querySelector("#output").innerHTML = x;Test and See‹/›
All browsers fully support the origin property:
property | |||||
origin | is | is | is | is | is |
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. |
---|
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‹/›
Location Reference:location.host property
Location Reference:location.hostname property
Location Reference:location.pathname property
Location Reference:location.protocol property