W3cubDocs

/Web APIs

location: origin property

The origin read-only property of the Location interface is a string 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 dependent;
  • 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

Value

A string.

Examples

js

// On this page, returns the origin
const 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
21Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
11Intranet sites are set to Compatibility View, which will emulate IE7 and omit window.location.origin.
15 5.1 3 18
21Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
14 5 1.0

© 2005–2023 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