dom / latest / location / origin.html /

location.origin

The origin read-only property of the Location interface is a USVString containing the Unicode serialization of the origin of the represented URL.

That is:

  • for URL using the http or https, the scheme followed by '://', followed by the domain, followed by ':', followed by the port (the default port, 80 and 443 respectively, if explicitly specified);
  • for URL using file: scheme, the value is browser dependant;
  • for URL using the blob: scheme, the origin of the URL following blob:. E.g "blob:https://mozilla.org" will have "https://mozilla.org".

Note: This feature is available in Web Workers

Syntax

string = object.origin;

Examples

// On this page, returns the origin
var result = window.location.origin; // Returns:'https://developer.mozilla.org'

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
origin
8
12
21
Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
11
Intranet sites are set to Compatibility View, which will emulate IE7 and omit window.location.origin.
15
5.1
3
18
21
Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
14
5
1.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Location/origin