Window location.origin
Example
Get the protocol, hostname and port number of the URL:
let origin = location.origin;
Try it Yourself »
Definition and Usage
The origin
property returns the protocol, hostname and port number of a URL.
The origin
property is read-only.
Note
If the port number is not in the URL, or if it is a default port like 80 (Http), or 443 (https), some browsers will not display the port number.
Syntax
location.origin
Return Value
Type | Description |
A string | 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. |
Browser Support
location.origin
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |