SeriousM
5/8/2014 - 11:49 AM

get executing script tag

get executing script tag

<script>
    /* another block */
</script>
<script data-test-value="xyz">
    //http://stackoverflow.com/a/2954896
    // this works because the processing of script blocks is serial 
    // and others does not exist in that moment of execution.
    // works with script-references
    // does NOT work with async's
    var toArray =Array.prototype.slice;
    var scripts = toArray.call(document.scripts);
    toArray.call(scripts[scripts.length - 1].attributes)
        .forEach(function(es){
            alert(es.nodeName + ': ' + es.nodeValue); // -> "data-test-value: xyz"
        });
</script>
<script>
    /* another block */
</script>