我正在製作一個可以讀取SVG元素的IE 11插件,用其他HTML包裝它,然後用新生成的HTML打開彈出窗口打印它。Crossrider:擴展找不到動態生成的iframe(IE 11)
我面臨的問題是,即使我在我的設置中打開了「在IFrame中運行」。該擴展程序無法找到頁面上的大部分iframe。請注意,我製作此插件的網站是https://app.powerbi.com。 PowerBI是使用Angular構建的,並且內嵌框架正在動態加載。
這裏是我的代碼:
background.js
appAPI.ready(function($) {
appAPI.browserAction.setResourceIcon('icon.png');
appAPI.browserAction.onClick(function() {
appAPI.message.toActiveTab('print');
});
});
extension.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>