For a fragment of HTML/JavaScript that gets loaded into a host web page dynamically, I need the JavaScript fragment to know about where it is declared. Is there a way of finding the tag that the currently executing JavaScript was loaded from?
The HTML fragment is loaded from the same host as the cur开发者_高级运维rent page using a jQuery ajax call and inserting the result into the DOM.
Edit:
What I really am trying to do, and the above would be one potential way of implementing it, is to have a fragment of HTML/JavaScript being loaded dynamically and a known initialization function be called by the host page with some parameters. Any portable solution that would allow for the worlds to meet would solve my problem.
You may use id attribute for your script tag and find it by #mylib
selector or find it using tag&attr selector script[src="mylib.js"]
.
精彩评论