【问题标题】:Crossrider: Extension cannot find dynamically generated iframes (IE 11)Crossrider:扩展无法找到动态生成的 iframe (IE 11)
【发布时间】:2016-09-10 01:38:41
【问题描述】:

我正在制作一个 IE 11 插件,它可以读取 SVG 元素,用其他 HTML 包装它,然后用新生成的 HTML 打开弹出窗口以打印它。

我面临的问题是,即使我在设置中打开了“在 IFrame 中运行”。该扩展程序无法在页面上找到大多数 iframe。请注意,我制作此插件的网站是https://app.powerbi.com。 PowerBI 是使用 Angular 构建的,并且 iframe 是动态加载的。

这是我的代码:

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>

【问题讨论】:

    标签: internet-explorer browser-extension crossrider ieaddon


    【解决方案1】:

    在 iframe 中运行 功能旨在在页面加载时在页面上存在的 iframe 上运行。因此,它不能在动态加载的 iframe 上运行。

    [披露:我是 Crossrider 的员工]

    【讨论】:

      猜你喜欢
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 2017-02-10
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多