Location origin Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

Location origin Property

❮ Location Object

Example

Return the protocol, hostname and port number of a URL. Assume that the current URL is https://www.w3schools.com:4097/test.htm#part2:

var x = location.origin;

The result of x will be:

https://www.w3schools.com:4097

Definition and Usage

The origin property returns the protocol, hostname and port number of a URL.

Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will not display the port number.

Note: This property is read-only.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
origin Yes 11.0 Yes Yes 15.0

Syntax

location.origin

Technical Details

Return Value: A String, representing the protocol (including ://), the domain name (or IP address) and port number (including the colon sign (:) of the URL. For URL's using the "file:" protocol, the return value differs between browsers

❮ Location Object