0

I want to make a website containing a frame (div would work as well) with an external page inside of it, once the user downloads a file on the page in the frame, I want to trigger an event. Filedownload is triggered by a form submission. Is this possible? Thanks. EDIT: I can code PHP, ASP, jQuery and a tiny bit of Java, but I'm always willing to learn more.

Could I replace the form's action to a different file which'll redirect the POST data to the original form action page but will also receive the GET data. I'm sorry I'm probably not using the right terms.

jewetnit
  • 41
  • 9
  • The solution depends on how the file is downloaded... If the download is triggered by a button click, simply trigger your event from inside the button click handler... – Šime Vidas Oct 25 '11 at 22:39
  • it's triggered by a form submission i believe – jewetnit Oct 25 '11 at 22:39

3 Answers3

0

When the user clicks the submit button on the form, jQuery can trigger a function to run.

jQuery("#downloadLink").click(function(){alert('user has clicked the download link');});

*Note:*This would execute when the user starts downloading, not once the download is complete.

EDIT: this would not require access to the external page's code, and you wouldn't have to manipulate the action of the form at all.

  • I should've noted, I don't have access to the external page's sourecode – jewetnit Oct 25 '11 at 23:05
  • If you don't have access to the actual form you're submitting, you could still use a jQuery click handler to detect if someone clicks the form submit button. If you want to do something with the information in the form then you could also use jQuery to read it out when the user clicks "Submit". – KopfaufAchseln Oct 25 '11 at 23:16
0

You can detect the start of a download with some tricks, but not the end of the download.

To detect the end of the download you you may be able to have the server than sends the download help you.

To detect the start have the download page first execute some javascript code that tells you "download started", something like window.parent.downloadStarted() and have a downloadStarted() function in the parent window.

Then after running that have the iframe redirect to the real page that does the download.

To detect the end of the download the program feeding the download would have to signal it. The best bet is to use APC and set a variable, then constantly poll a second page that checks if the variable was set or not, and reports back.

Ariel
  • 25,995
  • 5
  • 59
  • 69
0

Not mine, but I found this reference that supposedly uses AJAX http://www.sitepoint.com/forums/showthread.php?618233-Detecting-File-Download-Completion

To expand further: Browser event when downloaded file is saved to disk

You can use some gimmicky stuff to tell when the client has disconnected, but still seems like you might get false positives in some situations.

Community
  • 1
  • 1
Tim
  • 1,840
  • 2
  • 15
  • 12
  • seems to require more than just AJAX, I also should've noted, I don't have access to the external page's sourecode. – jewetnit Oct 25 '11 at 23:04