How to start automatic download of a file?

<script type="text/javascript">
setTimeout(function () { window.location = 'download url'; }, 5000)
</script>