0

I'm letting people include my JS script like

<script src='example.js' test='1'></script>

So my question is, how would i check if test is equal to 1 or 0 inside the script which it is loading?

any help is greatly appreciated!

  • 3
    `alert(document.currentScript.getAttribute("test"))` – dandavis Sep 25 '15 at 05:58
  • Before it loads the script, i want it to check if the script has the value of 1 or 0, this is ment to be done in pure JS! – Алексей Лагунов Sep 25 '15 at 05:59
  • you can point to it from another script. the easy way is to give the script tag an _id_. however, i'm not sure if you can see tags that have not executed yet. to wit: `document.getElementByTagName("script")` always returns a collection where the _document.currentScript_ is in the last position (w/o _defer_ being in play) – dandavis Sep 25 '15 at 06:00
  • you can see the pages: [DEMO][1] [DEMO 1][2] [1]: http://stackoverflow.com/questions/17769688/custom-attributes-in-a-script-tag [2]: http://stackoverflow.com/questions/14904378/get-data-attribute-of-script-tag – Ivin Raj Sep 25 '15 at 06:07
  • Are you sure the `test` attribute is retained in all browsers after parsing? It's not a standard attribute, and browsers have no obligation to keep stuff like that in memory. Different browsers react differently to errors, remember that! Why don't you play it safe and use a proper attribute like `data-test` or something. – Mr Lister Sep 25 '15 at 11:50

0 Answers0