Java Script

How to open PDFs in Iframe Onclick the Button

Spread the love

How to open PDFs in Iframe Onclick the Button –

How to open a PDF file in an Iframe

  • Example of HTML file given as bellow –
  • How to load PDFs in Iframe Onclick event in java script the Button
  • Click on button “Click here to open PDF” to open PDF in iframe.
  • placeFrame.src define path of PDF File.
<html>
<head>
</head>
<body>
	<p align="center"><iframe id="iFrameLocationId" style="display:none" width="650" height="350"></iframe></p>
	<p align="center"><input type="button" value="Click here to open PDF" onclick = "openPdfIframe()"/></p>
	<script type="text/javascript">
		function openPdfIframe(){
			var placeFrame = document.getElementById("iFrameLocationId");
			placeFrame.style.display="block";
			placeFrame.src = "dummy_pdf.pdf"; // pdf file location
		}
	</script>
</body>

Leave a Reply

Your email address will not be published. Required fields are marked *