Download file on page load not working

I've been trying to get a file to download when the page loads by doing this:

<div onload="download()"></div>
<a id="dl" style="display: none" 
    href="http://www.miniclip.com/games/base-jumping/en/base_jumping_miniclip.swf" 
    download>Download</a>

<script>
function download(){
   document.getElementById('dl').click();
}
</script>

What it's supposed to do is trigger a function when the page loads that "clicks" the hidden download link. However, this method isn't working and I don't know why.

Anybody know why?

Answers:

Answer
<script>
(function download() {
    document.getElementById('dl').click();
})()
</script>

This will execute your function right after instantiation.

Answer
<script>
window.location.href = 'http://www.miniclip.com/games/base-jumping/en/base_jumping_miniclip.swf';
</script>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.