Window location.origin

Example

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

let origin = location.origin;
Try it Yourself »

Description

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 stringThe 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 Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.