Bilberryfm
Bilberryfm

Reputation: 537

Downloading not started after windows.open()

I have controller where I generate and download the file. When user clicks "Download" button, this code is executed:

_statusWindow = window.open('downloadCSV', "_statusWindow");
_statusWindow.document.write('<div>  Please wait while we processing your request</div>');
_statusWindow.document.title = "Downloading...";

It points to controller downloadCSV, that generates file (without returning any views) So new window is open, when file is generated - downloading starts automatically and window will be closed once downloading is finished. This code works fine, when I dont have this single line:

_statusWindow.document.write('<div>  Please wait while we processing your request</div>');

But I want to append this line to show the message to user. WITH this line (as I show you in first code snippet), it starts downloading ONLY IF I click on button TWICE! And I have no idea why. When I click once - its just show the message, without calling controller and generating file, When I call it for second time - it's starts downloading...

Any suggestions, please HELP

Upvotes: 0

Views: 152

Answers (2)

Rajani B
Rajani B

Reputation: 203

can you give it a try, I am trying to open download as a iframe, and closing the window on load of iframe.. hope it may work..

 var win = window.open("","_statusWindow");
 var html = '<html><head><title>Base</title></head><body>Please wait while 
   we processing your request...</body></html>';
 var iframe = win.document.createElement('iframe');
 iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
 win.document.body.appendChild(iframe);
 var iframe2 = win.document.createElement('iframe');
 iframe2.src = "downloadCSV";
 iframe2.onload= win.close();
 win.document.body.appendChild(iframe2);

Upvotes: 1

Rajani B
Rajani B

Reputation: 203

I doubt whether the message stays on the window or not until the download finishes, can you please give a try of the below code..

var win = window.open("","_statusWindow");
var html = '<html><head></head><body>Please wait while we processing your 
request...</body></html>';
var iframe = win.document.createElement('iframe');
iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
iframe.onload = window.open("downloadCSV","_statusWindow");
win.document.body.appendChild(iframe);

Upvotes: 1

Related Questions