![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
currentscript
Advanced tools
document.currentScript
A polyfill of HTML5's document.currentScript
for IE 6-10 ONLY.
This polyfill will not work in IE11 because of a critical design choice made Microsoft ("Don't Call Me IE!") [1][2][3][4] in order to avoid consumers receiving an unnecessarily downgraded experience on websites that were making logic branch and feature decisions based on browser detection rather than feature detection.
However, Microsoft Edge (a.k.a. "Spartan", a.k.a. IE12) does natively support document.currentScript
. This is likely due in part to you lovely consumers upvoting this issue on the IE Platform Suggestion Forum, so thank you!
This polyfill is configured do its best to comply with the HTML spec's definition of the correct behavior for document.currentScript
.
More particularly, this will get the script
element that was the source of the nearest currently executing code but ONLY if said source script is being evaluated synchronously for the first time by the browser.
In other words, if code is being operated on after its initial evaluation (e.g. async callbacks, functions invoked by user actions, etc.), then document.currentScript
will always return null
.
If you are interested in getting the currently executing script [regardless of the source/trigger of the exection], take a look at JamesMGreene/currentExecutingScript instead.
Browser | Version | Works? | Notes |
---|---|---|---|
IE | 6 | Yes | Must use document._currentScript() . |
IE | 7 | Yes | Must use document._currentScript() . |
IE | 8 | Yes | |
IE | 9 | Yes | |
IE | 10 | Yes | |
IE | 11 | No! | IE removed script.readyState but didn't add document.currentScript yet! :astonished: See PSA for more info. |
Edge | * | Yes | Natively supports document.currentScript . |
* | * | Maybe...? | Only if the browser natively supports document.currentScript . |
npm install currentscript
Alternatively, you can download/clone its GitHub repo: JamesMGreene/document.currentScript
var scriptEl = document.currentScript;
var scriptEl = document._currentScript();
doNotDeferToNativeMethod
To support better cross-browser support, the default behavior of this polyfill in browsers other than IE 6-10 is to attempt to retrieve the native document.currentScript
accessor method and use it as a last-ditch fallback effort.
However, if you would prefer to disallow that fallback behavior, you can do so as follows:
document._currentScript.doNotDeferToNativeMethod = true;
FAQs
Polyfill of HTML5's `document.currentScript`
The npm package currentscript receives a total of 7 weekly downloads. As such, currentscript popularity was classified as not popular.
We found that currentscript demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.