拒绝访问Firefox浏览器中跨源对象上的属性“ __contentwindow__”的权限

时间:2018-11-26 14:28:37

标签: javascript pdf firefox iframe printing

当我尝试通过将URL加载到iframe元素来打印pdf文件时,它会引发异常拒绝访问Firefox浏览器中跨源对象的属性“ __contentwindow __” 。但是在Chrome浏览器中效果很好

这是Javascript代码:

var print = function(){

function closePrint () {
   document.body.removeChild(this.__container__);
}

function setPrint () {
  this.contentWindow.__container__ = this;
  this.contentWindow.onbeforeunload = closePrint;
  this.contentWindow.onafterprint = closePrint;
  this.contentWindow.focus(); // Required for IE
  this.contentWindow.print();
}

function printPage (sURL) {
    var oHiddFrame = document.createElement("iframe");
    oHiddFrame.onload = setPrint;
    oHiddFrame.style.visibility = "hidden";
    oHiddFrame.style.position = "fixed";
    oHiddFrame.style.right = "0";
    oHiddFrame.style.bottom = "0";
    oHiddFrame.src = sURL;
    document.body.appendChild(oHiddFrame);
  }
  printPage(url);
}

错误:

enter image description here

0 个答案:

没有答案