使用 iframe 的 Onload 事件
我希望有人能帮助我 - 我正处于放弃的边缘。我有一个页面,如果选择该页面,我希望将 PDF 文档加载到框架中。最初,代码有一个按钮,如果您单击它,它会打开 PDF '',我尝试更改该按钮,以便在页面加载时它必须打开 PDF,但没有成功。请问有人可以帮助我吗?
<html>
<head><title>Body onload example</title>
</head>
<script type="text/javascript">
function openPdf()
{
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display="block";
omyFrame.src = "myFile.pdf";
}
</script>
<body onload="openPdf();">
</body>
I hope someone can help me - I'm at the point of giving up. I've got a page, if the page gets selected I want the PDF document to load in a frame. Originally the code had a button where if you clicked it it opened the PDF '', I tried to change that so that if the page loads it must open the PDF but no luck. Please can someone help me?
<html>
<head><title>Body onload example</title>
</head>
<script type="text/javascript">
function openPdf()
{
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display="block";
omyFrame.src = "myFile.pdf";
}
</script>
<body onload="openPdf();">
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 body 内有一个具有适当 ID(“myFrame”)的 iframe - 尽管我假设您为了简洁起见跳过了它。此外,请确保“myFile.pdf”与您调用它的页面位于同一级别。请参阅 http://jsfiddle.net/g97zk/2/
尽管请记住,渲染 PDF在 iframe 中将导致它在大多数浏览器中下载。
You need to have an iframe with appopriate ID ("myFrame") inside the body - hough I'm assuming you skipped that for the sake of brevity. In addition make sure that "myFile.pdf" resides at the same level as the page you're calling it from. See http://jsfiddle.net/g97zk/2/
Although keep in mind, that rendering a PDF in an iframe will cause it to be downloaded in most browsers.