I wrote a very simple website for a friend, he needs to show a pdf in a page. Firstly I've tried with an iframe but I wasn't able to set the height to "100%".
<script type="text/javascript">
/*
* When the iframe is on a different subdomain, uncomment the following line
* and change "example.com" to your domain.
*/
// document.domain = "example.com";
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
}
};
window.onload = function () {
setIframeHeight(document.getElementById('mainContent'));
};
</script>
and this is the iframe in the body section
<iframe id="mainContent" src="URL_PDF" scrolling=auto frameborder=0 width="100%"></iframe>
It works but there is a problem when I try to visit the page with a smartphone (I tested it with android). In particular, the browser attempt to download the file instead of showing it, there is a method to avoid it?