Geeft het <script>
element wiens script op dit moment wordt uitgevoerd.
Syntax
var curScriptElement = document.currentScript;
Voorbeeld
Dit voorbeeld controleert of het script asynchroon wordt uitgevoerd:
if (document.currentScript.async) {
console.log("Wordt asynchroon uitgevoerd");
} else {
console.log("Wordt synchroon uitgevoerd");
}
Opmerkingen
Het is belangrijk om te weten dat dit geen referentie naar het script-element geeft als de code in het script wordt aangeroepen als een callback of event handler; het refereert alleen naar het element wanneer dit initieel wordt verwerkt.
Specificaties
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Document.currentScript' in that specification. |
Living Standard | Initiële definitie |
Browser compatibiliteit
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basisondersteuning | 29.0 | (Yes) | 4.0 (2.0) | Niet ondersteund | 16 | 8 |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basisondersteuning | 4.4 | (Yes) | (Yes) | (Yes) | ? | ? | 8 |