Skip to content

JavaScript 获取页面所有 Script 标签

Published: at 05:43 PMSuggest Changes

问题

期望获取页面上所有的 Script 标签,判断是否加载过 Js 文件

解决

function getScriptTag (Z) {
  const scripts = document.getElementsByTagName('script')
  const scriptList = []
  for (var i = 0; i < scripts.length; i++) {
    if (scripts[i].src) {
      scriptList.push(scripts[i].src)
    } else {
      scriptList.push(scripts[i].innerHTML)
    }
  }
  return scriptList
}

Previous Post
解决 Element el-tree 树状数据量大时卡顿问题
Next Post
CSS resize 属性详解