获取当前正在执行的,动态附加的脚本标签 [英] Getting the currently executing, dynamically appended, script tag

查看:40
本文介绍了获取当前正在执行的,动态附加的脚本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
我如何引用该脚本加载了当前正在执行脚本的代码?

如果在页面加载后动态添加了当前正在运行的脚本元素,是否有任何方法可以获取对它的引用?此答案问题不起作用,因为我不知道标签ID,并且连续添加多个标签后[scripts.length-1]方法失败.

Is there any way to get a reference to the currently running script element if it was appended dynamically after page load? The answers to this question do not work as I do not know the tag ID and the [scripts.length-1] method fails when multiple tags have been appended in succession.

推荐答案

由于正在执行的脚本大概知道"了它的名称,因此加载以下脚本应该起作用:

Since the executing script presumably "knows" the name it was loaded with the following should work:

for (var s, scripts = document.getElementsbyTagName ('script'), i = scripts.length; i--;)
  if ((s = scripts[i]).src.indexOf ('scriptname.js') < 0 && s.id && !test (s.id)) {
     alert ("Script " + s.src + " id " + s.id + " not yet processed");
  }

这篇关于获取当前正在执行的,动态附加的脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆