HTMLAnchorElement: origin 属性
HTMLAnchorElement 接口的只读属性 origin 返回一个字符串,其中包含 <a> 元素的 href 的 origin 的 Unicode 序列化。
具体的结构因 URL 类型而异。
- 对于使用
ftp:、http:、https:、ws:和wss:方案的 URL,它会返回后面跟着protocol//,再后面跟着。与hosthost相同,仅在不为协议默认端口时包含。port - 对于使用
file:方案的 URL,其值取决于浏览器。 - 对于使用
blob:方案的 URL,返回的是blob:后面的 URL 的 origin,但前提是该 URL 使用http:、https:或file:方案。例如,blob:https://mozilla.org将返回https://mozilla.org。
对于所有其他情况,返回字符串 "null"。
有关更多信息,请参阅 URL.origin。
值
字符串。
示例
js
// An <a id="myAnchor" href="https://mdn.org.cn/en-US/HTMLAnchorElement"> element is in the document
const anchor = document.getElementById("myAnchor");
anchor.origin; // returns 'https://mdn.org.cn'
规范
| 规范 |
|---|
| HTML # dom-hyperlink-origin-dev |
浏览器兼容性
加载中…
另见
- 它所属的
HTMLAnchorElement接口。