【问题标题】:print a created iframe content. Empty page打印创建的 iframe 内容。空白页
【发布时间】:2013-01-27 04:30:14
【问题描述】:

我有一个函数,但我找不到它为什么打印空白页。也只有 Opera 打印不是空页,它打印所有页面。不仅仅是 iframe。在 Chrome 中,如果我使用 srcdoc,我没有问题。 请大家帮忙

function printpage(src){
//create new image tag
var newImg = new Image();
newImg.onload = function(){ loading(); };
newImg.src = src;
newImg.style.height = "100%";
newImg.style.width  = "100%";

var ifrm = null;
ifrm = document.getElementById('iframe');
if(ifrm==null){
    ifrm = document.createElement("IFRAME"); 
    ifrm.style.width=853+"px";
    ifrm.style.height=1024+"px";
    ifrm.style.display="none";
    ifrm.id = "iframe";
    ifrm.name = "iframe";
    ifrm.width = ifrm.height = 0;
    document.body.appendChild(ifrm);
}else{
    //ifrm.contentWindow.Reset();
    document.body.appendChild(ifrm);
}
var s = '<img src ="'+src+'" width="100%" height="100%" ></img>'+
            '<script>'+
                'function printMe(){ '+
                  'window.print();'+
                  '}'+
            '</script>';
ifrm.src = "data:text/html;charset=utf-8," + escape(s);

console.log("new ifrm is ",ifrm);

var frameContent = (ifrm.contentWindow || ifrm.contentDocument || ifrm.window);

console.log("frameContent",frameContent);
frameContent.focus();
frameContent.print();

}

【问题讨论】:

    标签: javascript iframe printing joomla2.5


    【解决方案1】:

    我发现了问题:

    ifrm.style.display="none"; // The browser can't print content which is not displayed.
    

    我使用ifrm.style.visibility="hidden";隐藏元素

    【讨论】:

      猜你喜欢
      • 2012-03-20
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 2010-10-24
      相关资源
      最近更新 更多