document.currentScript is null

document.currentScript only returns the script that is currently being processed. During callbacks and events, the script has finished being processed and document.currentScript will be null. This is intentional, as keeping the reference alive would prevent the script from being garbage collected if it’s removed from the DOM and all other references removed.

If you need to keep a reference to the script outside of any callbacks, you can:

var thisScript = document.currentScript;

setInterval(() => console.log(thisScript.src), 2000);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)