W3cubDocs

/Web APIs

HTMLAnchorElement: origin property

The HTMLAnchorElement.origin read-only property 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".

Value

A string.

Examples

js

// An <a id="myAnchor" href="https://developer.mozilla.org/en-US/HTMLAnchorElement"> element is in the document
const anchor = document.getElementById("myAnchor");
anchor.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 17
26Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
No 15 5.1 3 18
26Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
14 5 1.0

See also

© 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/HTMLAnchorElement/origin