我正在使用 w3c 资源计时 API。window.performance.getEntriesByType("resource"); 这给出了包括 iframe 在内的资源列表。但是,要获取嵌入式 iframe 的资源,我需要获取 iframe 的性能对象,这需要我引用其 DOM 节点/元素。
var myiframe2 = $("#myiframe2");
var myiframeContentWindow = myiframe2[0].contentWindow;
var iframeContentPerf = myiframeContentWindow.performance;
问题是,如果我只知道 iframe 的 URL,如何获取 iframe 的节点引用,这就是我所知道的(与上面的代码示例不同,我不会知道 iframe 的 ID 或名称)。
除了遍历文档的元素然后过滤 iframe 并将 iframe 的 URL 与 Resource Timing API 返回的内容进行比较之外,是否有一种简单的方法来获取 iframe 的 DOM 节点(给定 iframe 的 URL)?