开发者

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

开发者 https://www.devze.com 2023-03-16 07:00 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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