Start Auto-download of File when page loads?

894359
894359 used Ask the Experts™
on
How do I set-up a webpage so as soon as it loads, a document will start downloading to the user's machine?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Full Stack Developer
Commented:
Try this code. Hope it will help you.
NOTE:- Replace your file name in "downloadURI" method call
<script type="text/javascript">
function downloadURI(uri, name) {
  var link = document.createElement("a");
  link.download = name;
  link.href = uri;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  delete link;
}
downloadURI("data:text/html", "raj.pdf");

</script>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial