Window location.origin property

Definition and Usage

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

origin The property is read-only.

Tip:If the port number is not in the URL or is the default port, such as 80 (Http) or 443 (https), some browsers will not display the port number.

Example

Get the protocol, hostname, and port number of the URL:

let origin = location.origin;

Try it yourself

Syntax

location.origin

Return value

Type Description
String

The protocol of the URL (including: //), domain name (or IP address), and port number (including the colon (:)).

For URLs using the "file:" protocol, the return values differ among different browsers.

Browser Support

All Browsers Support location.origin:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support