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.club.tw/en-US/HTMLAnchorElement"> element is in the document
const anchor = document.getElementById("myAnchor");
anchor.origin; // returns 'https://mdn.club.tw'
規範
| 規範 |
|---|
| HTML # dom-hyperlink-origin-dev |
瀏覽器相容性
載入中…
另見
- 它所屬的
HTMLAnchorElement介面。