文件:URL 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

Document 介面的只讀屬性 URL 以字串形式返回文件位置。

包含文件 URL 的字串。

示例

JavaScript

js
document.getElementById("url").textContent = document.URL;

HTML

html
<p id="urlText">
  URL:<br />
  <span id="url">URL goes here</span>
</p>

結果

規範

規範
DOM
# ref-for-dom-document-url①

瀏覽器相容性

另見

  • document.documentURI 屬性返回相同的值。