-1

Self Answering this question:

Using document.currentScript is not supported by IE.

Using

var scripts document.getElementsByTagName('scripts');
var script=scripts[scripts-1]

does not work asynchronously.

I ran into a very rare circumstance where using DOM selectors was not an option either.

ie document.getElementById('myScript');

Is there a way to execute the script where "this" refers to the script tag?

user2782001
  • 3,380
  • 3
  • 22
  • 41

1 Answers1

0

for previous discussion on this see

How may I reference the script tag that loaded the currently-executing script?

My solution was to do this...

<h1> 
     <script onload='new Function(this.innerHTML).call(this)' src=' '>
                if(this!=window){
                    this.parentNode.innerHTML='HELLO THERE!';
                }
     </script>
</h1> 

IE requires the SRC attribute to have at least one blank space. src='' will not work in IE.

Community
  • 1
  • 1
user2782001
  • 3,380
  • 3
  • 22
  • 41
  • Afaik setting `src` will block the inline script within a script tag. – Teemu Jun 11 '15 at 14:59
  • @Teemu Yeah. The if(this!=window) condition was not necessary in modern FF and IE for the reason you mention, but I left it there since I didn't test every browser version. – user2782001 Jun 11 '15 at 16:15