title: how to download a file on disk with specific location using javascript or jquery?
body: <blockquote>
    <p>i want to download a file automatically using javascript or jquery
    below is the code which i am using but that code open the file in new
    tab in browser not download in disk.</p>
  </blockquote>
  
  <pre><code>function SaveToDisk(fileUrl, fileName) {
      var hyperlink = document.createElement('a');
      hyperlink.href = fileUrl;
      hyperlink.target = '_blank';
      hyperlink.download = fileName || fileUrl;
  
      (document.body || document.documentElement).appendChild(hyperlink);
      hyperlink.onclick = function() {
         (document.body || document.documentElement).removeChild(hyperlink);
      };
  
      var mouseEvent = new MouseEvent('click', {
          view: window,
          bubbles: true,
          cancelable: true
      });
  
      hyperlink.dispatchEvent(mouseEvent);
  
      // NEVER use "revoeObjectURL" here
      // you can use it inside "onclick" handler, though.
      // (window.URL || window.webkitURL).revokeObjectURL(hyperlink.href);
  
      // if you're writing cross-browser function:
      if(!navigator.mozGetUserMedia) { // i.e. if it is NOT Firefox
         window.URL.revokeObjectURL(hyperlink.href);
      }
  }
  
  
          SaveToDisk('http://example.com/service/getUserImage/339/256', 'image.png');
  </code></pre>