Load PDFs in Iframe Onclick the Button

This is one of the way to display the PDF File using Iframe on click event using javascript. The PDF files will load the same Iframe on click the button using javascript.

This trick is useful in some places in website to load the more then one PDF File in single frame. on click the corresponding links.

load-pdf-in-iframe-on-click



Load PDF File using Iframe onclick the Button

<html>
<head>
</head>
<body>
<iframe id="myFrame" style="display:none" width="600" height="300"></iframe>
<input type="button" value="Open PDF" onclick = "openPdf()"/>
<input type="button" value="Open PDF1" onclick = "openPdf1()"/>
<script type="text/javascript">
function openPdf()
{
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display="block";
omyFrame.src = "1dummy.pdf";
}

function openPdf1()
{
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display="block";
omyFrame.src = "dummy_pdf.pdf";
}

</script>
</body>

Post a Comment

1 Comments