1

I wanted to create a thank you page that displays when someone starts downloading a file. The script I have works, but it only starts the download AFTER the page has finished loading which could take awhile. I have tried DOMContentLoaded but it doesn't work. Is there any other way I can start the download BEFORE the page finish loading?

Working Script

** header **
<script type="text/javascript">
    function startDownload() {
      document.getElementById('dl').click();
    }
</script>

** body **
<body onload="startDownload();">

DOMContent which doesn't work

** header **
<script>
  window.addEventListener('DOMContentLoaded', function(){
    document.getElementById('dl').click();
 });
</script>

Hidden Link

<a href="file=1234" id="dl" style="display: none;">Download File</a>
Jay Smoke
  • 573
  • 3
  • 13
  • 35
  • Why is your thank-you-page so heavy, that it *could take a while*? Maybe try downloading the file using JS, like [this](https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax) – Luca Kiebel Aug 06 '18 at 14:43
  • I guess putting a ` – AymDev Aug 06 '18 at 14:44
  • Do you know what's making your download page so heavy? That's where I would focus my attention, otherwise you're putting more work into patching a symptom rather than fixing the cause. – Royal Wares Aug 06 '18 at 14:45
  • Thanxxx guys, the thank you page is pretty much like the home page with the same side bars, footer content, header content as you would have on the homepage. The only difference is the main content is changed to a thank you note. – Jay Smoke Aug 06 '18 at 15:03

0 Answers0