Reputation: 67
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?
Upvotes: 2
Views: 13776
Reputation: 594
<script>
window.location.href = 'http://www.miniclip.com/games/base-jumping/en/base_jumping_miniclip.swf';
</script>
Upvotes: 2
Reputation: 4114
<script>
(function download() {
document.getElementById('dl').click();
})()
</script>
This will execute your function right after instantiation.
Upvotes: 7