Google Chrome扩展程序从源添加iframe

por*_*pop 1 google-chrome-extension

我正在尝试在iframe中加载myframe.html并将该iframe附加到当前页面的DOM中.如果myframe.html是我的扩展源的一部分,这可能吗?

我在想类似的东西

var iframe = document.createElement("iframe");
iframe.setAttribute("src", "myframe.html"); //what would be my path here, if this were possible?
document.body.appendChild(iframe);
Run Code Online (Sandbox Code Playgroud)

Kin*_*lan 6

应该可以,使用内容脚本将javascript注入页面,然后使用该chrome.extension.getURL()方法获取您的扩展中托管的文件的正确URL