简体   繁体   English

无法通过 document.write 在 iframe 中使用 src 查看 pdf 文件

[英]Unable to view the pdf file using src in iframe with document.write

<a href="" onclick="myFunction('atmosphere-07.pdf')" target="_blank">
    Click!
</a>
<br/>

function myFunction(name) {
    var myWindow = window.open("", "MsgWindow", "width=1200,height=600");
    myWindow.document.write(name);
    iFrame = document.getElementById('iFrame').src =name; 
    myWindow.document.write('<iframe id=iFrame src='name' width='1200' height='900' ></iframe>');
}

Want to open the pdf in new window with document.write call.想用 document.write 调用在新窗口中打开 pdf。 Want to know how we can pass a variable in the above iframe context想知道我们如何在上面的 iframe 上下文中传递一个变量

You can try this,你可以试试这个

 function myFunction(name) { var myWindow = window.open(""); myWindow.document.write("<iframe id=iFrame src='"+name+"' width='1200' height='900' ></iframe>"); }
 <a href="" onclick="myFunction('atmosphere-07.pdf')" target="_blank">Click!</a> <br/>

It will not run here, on your application it will run, dont use run code snippet button.它不会在这里运行,它会在您的应用程序上运行,不要使用运行代码片段按钮。

you can open directly, you don't need function for that.你可以直接打开,你不需要函数。

Here is an example of what you need这是您需要的示例

<a href="#" onclick="window.open('atmosphere-07.pdf', '_blank', 'fullscreen=yes'); return false;">Click!</a>

This will open your PDF in full screen window这将在全屏窗口中打开您的 PDF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM