Reputation: 11
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>
Upvotes: 1
Views: 1259
Reputation: 3333
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.
Upvotes: 1