0

I have this function:

function downloadAllReports() {
  $("#form\\:datatableReportAspectSpeed\\:btnDatatableReportAspectSpeed").trigger("click");
  $("#form\\:datatableReportAspectSpeed\\:btnDatatableReportAspectExcessDriving").trigger("click");
  $("#form\\:datatableReportAspectSpeed\\:btnDatatableReportAspectDailyHours").trigger("click");
  $("#form\\:datatableReportAspectSpeed\\:btnDatatableReportAspectRestrictedTime").trigger("click");
  $("#form\\:datatableReportAspectSpeed\\:btnDatatableReportAspectPreventiveDriving").trigger("click");
}

I call it from a link, the idea is that I want this function to click to 5 links i have. It just clicks the first one.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 1
    This is probably a security limitation of the browser to prevent malicious code opening multiple links. I'd suggest changing your logic to programmatically perform whatever action is required instead of faking events in the DOM. – Rory McCrossan Nov 30 '18 at 14:55
  • 1
    r/limitation/feature :) – Taplar Nov 30 '18 at 14:57
  • Rory is right. But, I am sure you can achieve this using window.location. Please check this: https://stackoverflow.com/questions/18451856/how-can-i-let-a-user-download-multiple-files-when-a-button-is-clicked – Rehmat Nov 30 '18 at 14:57
  • @Rehmat you'll have the same problem there too, as the browser will stop you spamming new windows. You could potentially use `setTimeout()` to space out the calls, but that's a really hacky workaround. – Rory McCrossan Nov 30 '18 at 14:58
  • @RoryMcCrossan: Yes, the best and easiest solution will be to zip all the files, I mean if he is trying to give file downloads. – Rehmat Nov 30 '18 at 15:01
  • Yes, I am trying to download all these files (5 files), they come from 5 different datatables – Marco Cabrejos Malma Nov 30 '18 at 16:09

0 Answers0