0

我正在尝试将库printjs与 Polymer 3.0 一起使用。printjs 能够打印 DOM 中的特定节点,而无需在新窗口中打开它。它的工作原理是创建一个隐藏的 iframe 并附加节点的克隆,然后打印该 iframe。但是,我只在 Firefox 上遇到了一个问题,我认为这与这篇 StackOverflow 帖子有关:Firefox removes web component properties when appended inside iframe

当节点(一个 Polymer Web 组件)附加到 iframe 时,this._enableProperties is not a function会引发错误。此外,所有 Polymer 属性都消失了(我已经覆盖了 cloneNode 以将属性从一个节点复制到它的克隆节点——这是让它在 Chrome/Safari 上工作所必需的)。

this._enableProperties 看起来像是在将节点附加到 DOM(通过其 connectedCallback)时由 Polymer 自动调用的。但是,由于 Firefox 奇怪的 iframe 隔离,节点一旦附加到 iframe 就会丢失 this._enableProperties。

// connectedCallback in properties-mixin.js from the Polymer source code
connectedCallback() {
  if (super.connectedCallback) {
    super.connectedCallback();
  }
  this._enableProperties();
}
// from printjs source code
var printDocument = iframeElement.contentDocument || iframeElement.contentWindow.document;
printDocument.body.appendChild(params.printableElement); // => Uncaught TypeError: this._enableProperties is not a function

这种行为有什么解决方法吗?谢谢!

4

0 回答 0