I do not believe this is possible at all (except by downloading a
zipped file). The JS in the browser is not allowed to initiate
downloads because it has no access to local filesystem. Downloads must
explicitly initiated by the user by clicking and approving the save.
This is a security feature of all browsers.