我需要使用pdf.js呈现页面。 从视图中,我将viewer.html插入到iframe中,并尝试获取其contentDocument。
var direccion = '<?php echo base_url() ?>'+doc[xid].relativepathfile + doc[xid].adjnombre;
html = '<iframe src = "<?php echo base_url() ?>vendors/pdf/web/viewer.html?file='+direccion+'" width="100%" id = "fraViewDocumentsPDFViewer" runat = "server" height="100%"> </iframe>';
$("#superior").append(html);
iFrame = document.getElementById('fraViewDocumentsPDFViewer');
console.log(iFrame.contentDocument);
变量iFrame是全局变量。
console.log(iFrame.contentDocument);
的结果是:
<html>
<head></head>
<body></body>
</html>
如果我从Chrome控制台运行iFrame.contentDocument
,它会向我显示正确的内容,但我不明白所缺少的内容。