gpt4 book ai didi

javascript - Chrome 扩展程序在检测 iframe 时失败

转载 作者:行者123 更新时间:2023-11-28 02:44:25 26 4
gpt4 key购买 nike

基本上我想做的是检测 G+ 主页中包含的帧数,当然我确实使用内容脚本

扩展的 Js 文件:

var myIframes;
window.addEventListener('load'
,function()
{
//If the window location matches the G+ home page
//Log number of frames contained within it
if(window.location.href.match("https://plus.google.com/u/0/"))
{
console.log('G+ loaded');

myIframes = document.getElementsByTagName('iframe');
console.log(myIframes.length);
}
}
,false);

执行这段代码的o/p日志是:

G+ loaded

2

现在出现了奇怪的部分,当我尝试从检查器控制台中访问myIframes变量长度时,我得到了8帧。

所以我的问题是“怎么会!”myIframes 变量不应该保持第一次评估时的样子吗?

最佳答案

document.getElementsByTagName('iframe') 返回一个节点列表。

节点列表为live ,当 DOM 改变时它们会更新。

关于javascript - Chrome 扩展程序在检测 iframe 时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12138442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com