0

I have created a success page on drupal 8 to download a file once redirected. Is there anyway to trigger downloading the file automatically based on a condition

For example if the page has an attribute download <a class="cta download-pdf" download="" href="/downloads/aim-brochure-mib.pdf">Download Brochure</a> inside the markup it would automatically download the file based on the address. Was thinking of using jquery/javascript to accomplish this.

clestcruz
  • 1,081
  • 3
  • 31
  • 75

1 Answers1

1

After redirecting that page inside document ready you can trigger your anchor tag.

$(function() {
//Check condition if any
$('.download-pdf').trigger('click');
});
4b0
  • 21,981
  • 30
  • 95
  • 142
  • I've tried this recently it doesn't seem to trigger the anchor link and found the cause a solution for it https://stackoverflow.com/questions/20928915/jquery-triggerclick-not-working – clestcruz Nov 06 '17 at 07:05