我有一机显示从同一来源装载的国防军。
<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进行。