I have an iframe embedding a pdf file but I want to ensure that the iframe extends its height automatically according to the contents in it so that the iframe scrolling bars are not shown, but every time I try the results comes unexpected here are my sample code
Here is what I tried
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Iframe</title>
<style>
iframe{
width: 100%;
border: 2px solid #ccc;
}
</style>
</head>
<body>
<iframe src="demo.pdf" id="myIframe"></iframe>
<script>
var iframe = document.getElementById("myIframe");
iframe.onload = function(){
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';
}
</script>
</body>
</html>