HTMLScriptElement: src プロパティ
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
src
は HTMLScriptElement
インターフェイスのプロパティで、外部スクリプトの URL を表す文字列です。文書内に直接スクリプトを埋め込む代わりに使用することができます。
これは <script>
要素の src
属性を反映したものです。
値
文字列です。
例
このコードは URL が https://example.com
であるウェブサイト上で動作していると想定します。
html
<script id="script-with-src" type="module" src="/main.js"></script>
<script id="script-without-src" type="module"></script>
js
const script_with_src = document.getElementById("script-with-src");
console.log(script_with_src.src); // 出力: "https://example.com/main.js"
const script_without_src = document.getElementById("script-without-src");
console.log(script_without_src.src); // 出力: ""
仕様書
Specification |
---|
HTML # dom-script-src |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
src | ||||||||||||
Can be set with a TrustedScriptURL instance |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.