Socket
Socket
Sign inDemoInstall

currentscript

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    currentscript

Polyfill of HTML5's `document.currentScript`


Version published
Weekly downloads
89
increased by50.85%
Maintainers
1
Install size
42.6 kB
Created
Weekly downloads
 

Readme

Source

document.currentScript

GitHub Latest Release Build Status Sauce Test Status Dependency Status Dev Dependency Status

Sauce Test Status

A polyfill of HTML5's document.currentScript for IE 6-10 ONLY.

Public Service Announcement (PSA)

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!

Overview

Strict

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.

Loose

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 Compatibility

BrowserVersionWorks?Notes
IE6YesMust use document._currentScript().
IE7YesMust use document._currentScript().
IE8Yes
IE9Yes
IE10Yes
IE11No!IE removed script.readyState but didn't add document.currentScript yet! :astonished: See PSA for more info.
Edge*YesNatively supports document.currentScript.
**Maybe...?Only if the browser natively supports document.currentScript.

Installation

NPM

npm install currentscript

GitHub

Alternatively, you can download/clone its GitHub repo: JamesMGreene/document.currentScript

Usage

IE 8-10

var scriptEl = document.currentScript;

IE 6-7

var scriptEl = document._currentScript();

Configuration

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;

Other Documentation

Errata

Keywords

FAQs

Last updated on 25 Oct 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc