开发者

How can I find the <script> element where my JavaScript is declared? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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"].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜