【发布时间】:2023-04-06 12:29:02
【问题描述】:
我想使用 Firefox 插件 sdk 编写扩展程序,并且我需要知道一个页面的所有 iframe(嵌套的,可能是跨域的)的总数。为此,我使用了 pageMod 和以下 contentScript(每个 iframe 都会向顶部窗口打招呼,因此我们可以跟踪它们的编号):
setTimeout(function(){
window.top.postMessage('I am a new iframe, url : ' + window.location.href
,'*');
},1000);
我通过以下代码收听来自 iframe 的消息:
window.addEventListener('message',function(event) {
number_of_frame++;
},false);
【问题讨论】:
标签: javascript iframe firefox-addon-sdk