HTMLScriptElement: src-Eigenschaft
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.
Die src
-Eigenschaft des HTMLScriptElement
-Interfaces ist ein String, der die URL eines externen Skripts darstellt; dies kann als Alternative zur direkten Einbettung eines Skripts innerhalb eines Dokuments verwendet werden.
Sie entspricht dem src
-Attribut des <script>
-Elements.
Wert
Ein String.
Beispiele
Nehmen Sie an, der Code läuft auf einer Website, deren URL https://example.com
ist.
<script id="script-with-src" type="module" src="/main.js"></script>
<script id="script-without-src" type="module"></script>
const script_with_src = document.getElementById("script-with-src");
console.log(script_with_src.src); // Output: "https://example.com/main.js"
const script_without_src = document.getElementById("script-without-src");
console.log(script_without_src.src); // Output: ""
Spezifikationen
Specification |
---|
HTML # dom-script-src |
Browser-Kompatibilität
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.