Start Auto-download of File when page loads?

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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Full Stack Developer
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"); = name;
  link.href = uri;
  delete link;
downloadURI("data:text/html", "raj.pdf");


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