gpt4 book ai didi

javascript - windows.open() 之后未开始下载

转载 作者:行者123 更新时间:2023-12-01 03:05:56 25 4
gpt4 key购买 nike

我有 Controller ,可以在其中生成和下载文件。当用户单击“下载”按钮时,将执行以下代码:

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

它指向 Controller downloadCSV,生成文件(不返回任何 View )因此,新窗口打开,当文件生成时 - 下载自动开始,下载完成后窗口将关闭。当我没有这一行时,这段代码工作正常:

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

但我想附加此行以向用户显示消息。使用这一行(正如我在第一个代码片段中向您展示的那样),仅当我单击按钮两次时它才会开始下载!我不知道为什么。当我单击一次时 - 它只是显示消息,而不调用 Controller 并生成文件,当我第二次调用它时 - 它开始下载...

有什么建议,请帮忙

最佳答案

你能尝试一下吗,我正在尝试以 iframe 的形式打开下载,并在加载 iframe 时关闭窗口..希望它可以工作..

 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);

关于javascript - windows.open() 之后未开始下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46189178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com