我正在制作一个 IE 11 插件,它可以读取 SVG 元素,用其他 HTML 包装它,然后使用新生成的 HTML 打开弹出窗口以打印它。
我面临的问题是,即使我在设置中打开了“在 IFrame 中运行”。该扩展程序无法在页面上找到大多数 iframe。请注意,我制作此插件的网站是https://app.powerbi.com。PowerBI 是使用 Angular 构建的,并且 iframe 正在动态加载。
这是我的代码:
背景.js
appAPI.ready(function($) {
appAPI.browserAction.setResourceIcon('icon.png');
appAPI.browserAction.onClick(function() {
appAPI.message.toActiveTab('print');
});
});
扩展.js
function tryPrint($) {
console.log('===', document.location.href , '===')
}
appAPI.ready(function($) {
appAPI.message.addListener(function(msg) {
if(msg === 'print') tryPrint($);
});
});
使用上面的代码,当我在浏览器中单击附加按钮时,我只看到以下输出:
=== https://app.powerbi.com/groups/me/reports/4dba04c3-8c3e-4e9e-abb8-a1fa58165928/ReportSection ===
=== https://app.powerbi.com/ewaIsolation.cshtml = ==
但是,以下 iframe 会动态添加到页面中,并且扩展程序似乎找不到它。
<iframe sandbox="allow-scripts" name="visual-sandbox" class="visual-sandbox" src="/sandbox?plugin=YourVisual1456308971941" style="width: 1630.17px; height: 922.83px;"> . . . </iframe>