最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why do querySelector and querySelectorAll NOT iterate within an iframe? - Stack Overflow

programmeradmin0浏览0评论

This works:

parent.document.getElementById('iframeID').contentWindow.document.querySelectorAll('*[id^="elementId"]');

But this doesn't:

parent.document.getElementById('iframeID').querySelectorAll('*[id^="elementId"]');

According to querySelectorAll's reference:

The Element method querySelectorAll() returns a static (not live) NodeList representing a list of elements matching the specified group of selectors which are descendants of the element on which the method was called.

If contentWindow is a descendant of the iframe element, shouldn't the iframe element be recursively iterated until, eventually, contentWindow and document are encountered, as it is the case with, for example:

<div id="div1">
  <div id="div2">
    <div id="div3">
      <div id="div4">
        <div id="div5">

        </div>
      </div>
    </div>
  </div>
</div>


<script>
console.log(document.getElementById("div1").querySelectorAll('div'));
</script>
发布评论

评论列表(0)

  1. 暂无评论