【问题标题】:Resizing a hidden-frame调整隐藏框架的大小
【发布时间】:2014-03-17 17:14:38
【问题描述】:

我正在尝试将网页加载到隐藏框架(sdk/frame/hidden-frame)中,然后呈现它的屏幕截图。我可以很好地获得屏幕截图,但框架大小不合适。使用如下代码渲染截图

var hiddenFrames = require("sdk/frame/hidden-frame");
let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
    onReady: function() {
        this.element.contentWindow.location = "http://example.com";
        let self = this;
        this.element.addEventListener("DOMContentLoaded", function() {
            var cnvs = self.element.contentDocument.createElement("canvas");
            var width = self.element.contentDocument.body.clientHeight; //for some reason clientWidth is 0 for www.example.com
            var height = self.element.contentDocument.body.clientHeight;
            cnvs.width = width;
            cnvs.height = height;
            var ctx = cnvs.getContext("2d");
            console.log(width+" "+height);
            ctx.drawWindow(self.element.contentWindow, 0, 0, width, height, "rgb(255,255,255)");
            console.log(cnvs.toDataURL());
        }, true, true);
    }
}));

我已经尝试过改变 iframe 的宽度和高度

this.element.width = "1600";
this.element.height = "900";

resizeTo()改变element.contentWindow的大小,改变body的大小。他们似乎都没有影响最终的截图,看起来像

【问题讨论】:

  • 如果 iframe 隐藏了为什么要调整它的大小。
  • 这样截图就可以正常渲染了。

标签: javascript html firefox firefox-addon firefox-addon-sdk


【解决方案1】:

尝试在包含 iframe(或包含 iframe 的脚本)后将其添加到父页面上。

$('iframe').load(function(){
    $(this).css({
       width: 1600,
       height:  900
    });
});

【讨论】:

  • 我试过了,但它不起作用。 Firefox 的 XUL iframe 对象与普通的 iframe 对象不同
  • 没有可用的 jquery,这是 firefox 插件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-13
  • 1970-01-01
相关资源
最近更新 更多