Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh/reload embed of application/pdf?

I have an embed code using application/pdf to show a pdf document on the page.

I used javascript to change the src attribute of the embed, which a link is clicked. then confimed using alerts to see that the src did change.

but the same pdf is still showing on the page.

How do I refresh/reload the embed tag (not the whole page)? I think this will fix it.

like image 217
sneaky Avatar asked Mar 20 '12 16:03

sneaky


1 Answers

How do you embed the PDF? If you are using an iframe, you can use the reload method.

<iframe id="myIframe" src="your.pdf" height="200" width="200"></iframe>

<script language="javascript" type="text/javascript">
    getElementById('myIframe').contentDocument.location.reload()
</script>

You can also append a random string (like the current timestamp) as a GET parameter to the PDF URL to make sure the browser doesn't use its cache.

like image 155
Fabian Avatar answered Sep 30 '22 00:09

Fabian