3

I am using

window.open("http://something...")

to open a pop-up window which shows a PDF file with some report on it when certain ajax success gets hit. However my PDF file doesn't show the updated data every-time I open the pop-up window. If I manually hit the F5 or refresh the page it shows the updated data. I tried something like this but to no avail.

window.open("http://something...").location.reload();

How can I refresh the pop-up window everytime it loads.

Bibek Aryal
  • 545
  • 9
  • 28

1 Answers1

2

You can append a timestamp into the url to avoid the browser cache

var url = "http:/myurl/myFile.pdf?"+ Date.now();
window.open(url);

for older browsers that doesn't support Date.now() you can use new Date().getTime();

Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30
  • 1
    What about `"http:/myurl/myFile.pdf?"+ Date.now()` – putvande Aug 09 '16 at 11:43
  • Ok i feel extremely stupid but I did try both + new Date().getTime(); and Math.random() etc. and it wasnt working before. Seems like I was misplacing "?" somewhere. This does solve my problem but I would love to know how to refresh the pop-up window too – Bibek Aryal Aug 09 '16 at 11:47
  • 1
    @BibekAryal here is a way how to refresh de window https://plnkr.co/edit/9BEyCqCnUWzq8B5jE8ac?p=preview – Vladu Ionut Aug 09 '16 at 11:54