English 中文(简体)
富兰州在一波一带出现交叉差错,而国防军也存在同样的差错。
原标题:Firefox throws cross-origin error on iframe with same-origin PDF

我有一机显示从同一来源装载的国防军。

<iframe id="pdfIframe" src="/example.pdf"></iframe>

当我管理这份联合材料以检查单体是否装载时,我收到一份<条码>安全通行证/代码>或<条码>。

iframeReady(document.getElementById( pdfIframe ), () => {
  console.log( iframe loaded )
))

/**
 * Execute callback when iframe is *actually* loaded. Ignores load events for
 * the "dummy" document that s loaded when an iframe is added to the DOM, and
 * before the src is loaded.
 *
 * Adapted from an answer on StackOverflow:
 * https://stackoverflow.com/a/24603642/877574
 */
function iframeReady(iframe, fn) {
  checkLoaded()

  function checkLoaded() {
    const doc = iframe.contentDocument || iframe.contentWindow?.document
    // We can tell if there is a dummy document installed because the dummy document
    // will have an URL that starts with "about:".  The real document will not have that URL
    if (doc && doc.URL.indexOf("about:") !== 0) {
      // set event listener for DOMContentLoaded on the new document
      doc.addEventListener("DOMContentLoaded", fn)
    } else {
      // still same old original document, so keep looking for content or new document
      setTimeout(checkLoaded, 1)
    }
  }
}

我知道,或许会认为,由于在单体装载了<条码>:空白<>/代码>时,会发生错误。 但我已核实情况并非如此。 在iframe装满了人民抵抗力量之后,我可以这样做,并触发例外情况:

pdfIframe.contentDocument // null
pdfIframe.contentWindow.document // triggers exception

同样的法典在 Chrome进行。

问题回答

When using the built-in pdf viewer in Firefox to load a pdf, the iframe ends up with domain === "pdf.js" - therefore it is not same origin as the parent, therefore the issue.

与此有关的问题涉及Catherine s bugzilla——但MAIN(或仅指)的谈话点是无法打电话. 印()在iframe上打印PDF。

这显然至少得到部分处理,例如pdfIframe.contentWindow.print()

也可获得<>t其他方法/产品,但不得文件

一个解决办法是:

那么,你的框架应当使用。

<iframe 
  id="pdfIframe"
  src="/pdf/web/viewer.html?file=/example.pdf"></iframe>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签