javascript – How to display pdf from db in iframe

javascript – How to display pdf from db in iframe

Try making a full URL out of the src path, and dont include any spaces in the path. So, something like this:

omyFrame.src = http://example.com/pdfs/PRICE%20LIST.pdf;

Ive just been playing around with manipulating an iframe this way, and it seems to work.

I know you said you are getting these PDFs from a DB, that you arent trying to load a specific file, but for this to work with an iframe it would be best if your server would serve up the contents of each PDF from a specific URL.


OK, so, based on your comments below, you could use a link like this:

<a href=javascript:void(0)
  onclick=openPdf(download.php?filename=<?php echo $name;?>)
  title=click to download>VIEW <span class=glyphicon glyphicon-paperclip
  style=font-size:20px; color:blue></span>
</a>

Then modify openPdf() like this:

function openPdf(src)
{
  var omyFrame = document.getElementById(myFrame);
  omyFrame.style.display=block;
  omyFrame.src = src;
}

javascript – How to display pdf from db in iframe

Leave a Reply

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