6

I have read at least 40-50 posts on this topic and none of the solutions really do what i want. I 'command' my WinCE 6.0 board to create a backup file through AJAX request and then i want to save this file to local WS.

I have the following javascript code that is called once the AJAX request completes:

function DownloadControllerBackupDB(theResult)
{
   if(typeof(theResult.Filename) != undefined)
   {
      var myFileLocation = '/data/' + theResult.Filename;

      location.href = myFileLocation;
   }
   else
   {
      Error("Backup failed !");
   }
}

I also tried this approach (instead of the 'location.href' technique):

function SaveToDisk(fileURL, fileName) 
{
    var save = document.createElement('a');

    save.href = fileURL;
    save.target = '_blank';
    save.download = fileName || 'unknown';

    var event = document.createEvent('Event');
    event.initEvent('click', true, true);
    save.dispatchEvent(event);
    (window.URL || window.webkitURL).revokeObjectURL(save.href);
}

Both 'techniques' endup @ the same result in chrome 50, the file is indeed saved to disk in the local folder dedicated to user's file download...

I would want the browser to ask me (with a file requester) before saving this file to disk so i can decide where to put it.

I read somewhere that you can set an option in chrome (and probably other browsers) to force it asking before saving files but i think this is unacceptable to ask a user to do (due to the complexity of the operation).

Is there anyway to 'Force' the browser to ask before saving a linked file ?

Thanxs

Philippe Brodeur
  • 131
  • 1
  • 3
  • 8
  • 1
    No. That behavior is determined by the user and the user alone. –  May 04 '16 at 19:37
  • 2
    I believe this question to be [answered here](http://stackoverflow.com/a/15928305/35070), although the *question* itself is not necessarily a duplicate. In short, the browser controls how file saving works, not the web application. – phihag May 04 '16 at 19:37
  • 1
    It is the user-agent (in this case your browser) that decides what to do with the file. Both Chrome and Firefox have settings to let you choose a specific folder, or to ask every time. You can't decide that from the webpage. – some Sep 26 '16 at 01:32

1 Answers1

-2
   let a = document.createElement('a');
   a.href = 'https://www.google.ru/logos/doodles/2016/2016-hockey-world-championship-5085766322487296.2-hp.jpg';
   a.download = true;
   var event = document.createEvent('Event');
   event.initEvent('click', true, true);
   a.dispatchEvent(event)
woland
  • 129
  • 6
  • Yeah, this is most likely the second approach i described above and gives the same result. I havent found anyway yet to force he browser asking for location before saving (instead of saving directly to the download folder). – Philippe Brodeur May 14 '16 at 21:21
  • 1
    @PhilippeBrodeur : It may be too late. I am also looking for the same solution. Did you ever had chance to find any solution on this? – Mohan Oct 19 '16 at 13:10
  • 1
    No i haven't. It really looks like the web browser (client) enforces security by letting the user choose whatever (or not) he wants to be prompted for file download. So in every browser, you have to set it manually. In chrome for example: Settings->Advanced settings->Downloads->check box 'Always ask where to save files' (i am translating from my french UI so there might be some variance). – Philippe Brodeur Dec 16 '16 at 15:52