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>