0

I'm currently porting a nodejs / angular webapp to Windows using nodewebkit. Everything has been working pretty well for now but I'm facing a litle problem when I want the user to download a file.

In order to start the download with the save file Dialog, I use a simple window.open(url) where url can be a link to any kind of files. This line actually do it's job and pop the window dialog for saving a file, but at the same time, a blank node-webkit page appears.

I've been trying to mess around with node-webkit for a while without managing to remove this blank page.

As anyone experienced the same kind of behavior ? I'll be interested in any lead, I'm not into the js stuff for long so I may have missed something obviouvs.

Have a nice wathever time of the day it is where you live !

Furzel
  • 606
  • 8
  • 18
  • 1
    That's the expected behaviour for `window.open()`. Read this: https://developer.mozilla.org/en-US/docs/Web/API/Window.open – emerson.marini Nov 25 '13 at 22:33
  • Ok so I did miss something obvious here ... using `location.href = url` instead seems to do the trick. Thanks a lot ! – Furzel Nov 26 '13 at 09:00
  • 1
    You should put your own comment up as answer and accept it so people can see it's solved. ;) –  Mar 05 '14 at 14:10

2 Answers2

1

a more better solution is found here

Step 1 In your html file, add a Input tag block like below:

<input id="export_file" type="file" nwsaveas style="display:none" nwworkingdir=""/>

Step 2 Add a new function in your javascript file like below:

function saveFile(name,data) {
    var chooser = document.querySelector(name);
    chooser.addEventListener("change", function(evt) {
      console.log(this.value); // get your file name
     var fs = require('fs');// save it now
fs.writeFile(this.value, data, function(err) {
    if(err) {
       alert("error"+err);
    }
});
    }, false);

    chooser.click();  
  }

Step 3 Save your file where ever you like by using saveFile(name,data) function like below:

...

_exportCSV="you data to save";

saveFile('#export_file',_exportCSV);

...
0

As questioner said to be working:

location.href = url

Is the correct usage.

Jack
  • 3,632
  • 7
  • 45
  • 67