1

i have a page in joomla that i am generating a pdf off of using the pdfmyurl service. to call the service you click a link. ie:

<a href="http://pdfmyurl.com?url=http://mywebsite.com/mypage&-R=0mm&-L=10mm&-s=Letter&--print-media-type&--footer-line&--filename=myfilename.pdf">click to generate pdf</a>

so you click a link on the main page which opens a "pdf-able" page in a popup window which then has a link to the above. (this is how joomla operates with printing pages).

this all works perfectly. but, i would like to close the popup when the link is clicked but AFTER the pdf is generated. if i use onclick="window.close();" method in the link the window closes before the pdf is generated.

i would like to solve this using jquery.

liz
  • 483
  • 1
  • 7
  • 16

2 Answers2

0

Use window.open, keep a reference to the window, and then go ahead and trigger window.close() when the PDF is finished loading (instead of the href). the only question is -- do you have any hooks to determine when the PDF has completed loading?

Reference: http://www.quirksmode.org/js/popup.html (mdn isn't working for me, but here's thelink: https://developer.mozilla.org/en-US/docs/DOM/window.open)

Nirvana Tikku
  • 4,105
  • 1
  • 20
  • 28
  • no hooks, the pdf loads into the browser as a download. i have window.open to open the window already... the only thing is that the window may lose focus after the browser download interface displays? – liz Jan 22 '13 at 21:14
  • check this clever hack out: http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download. i'm not familiar enough to know if you can write back end code on joomla, though. – Nirvana Tikku Jan 23 '13 at 04:33
  • i think the problem is that i am not GET/POST-ing... its just a simple link to the pdfmyurl site. – liz Jan 23 '13 at 17:28
  • well, you're still making a GET or a POST request for the PDF, the question is do you have control of that request (that returns the PDF)? if not, then you're not going to be able to take advantage of that hack.. :/ – Nirvana Tikku Jan 23 '13 at 17:29
  • nope no control... will have to think of something else.. maybe a timer on the link click – liz Jan 23 '13 at 22:32
0

create a link or element with 'closePdf' id:

 $('#closePdf').click( function() { 
      $('#whateverYourPDFContainerIdIs').remove(); 
 });
Adunahay
  • 1,551
  • 1
  • 13
  • 20