javascript中的下载文件在Chrome中不起作用 [英] Download file in javascript is not working in Chrome
本文介绍了javascript中的下载文件在Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是代码
function ExportToExcel() {
if ($("#dateRange").val() != "") {
var frm = $("#frmProjectReport").serialize();
var url = "/Reports/ProjectExcelReport?" + frm;
Download(url);
}
}
function Download(url) {
alert(url);
//var win = window.open(url, "DownloadWin", "resizable=0,status=0,toolbar=0,width=600px,height=300px");
var win = window.open(url, "DownloadWin", "width=600px,height=300px,scrollbars=yes ,menubar=no,location=no,left=0,top=0")
win.focus();
win.moveTo(100, 100);
}
它可以在除chrome之外的所有浏览器中使用.
its working in all browser except chrome.
我也使用了以下代码作为框架,但是在海量数据的情况下它不起作用.
I have used frame also as below code but it does't work in case of huge data..
function Download(url) {
try {
$("#fileIframe").html("");
var iframe = $('<iframe name="postframe" id="postframe" class="hidden" frameBorder="0" src="about:none" />');
$('#fileIframe').append(iframe);
$('#frmProjectReport').attr("action", url);
$('#frmProjectReport').attr("method", "post")
$('#frmProjectReport').attr("target", "postframe")
$('#frmProjectReport').submit();
//win = window.open(url, "DownloadWin", "width=600px,height=300px,scrollbars=yes ,menubar=no,location=no,left=0,top=0")
//win.focus();
//win.moveTo(100, 100);
}
catch (e) {
alert(e)
}
}
推荐答案
这是我们使用IFRAME
导出excel文件的方式:
Here is the way we export an excel file using an IFRAME
:
function download(src){
var ifr = document.createElement('iframe');
ifr.style.display = 'none';
document.body.appendChild(ifr);
ifr.src = src;
ifr.onload = function(e){
document.body.removeChild(ifr);
ifr = null;
};
}
它适用于所有浏览器,并且具有不弹出窗口的优点.
It works in all browsers, and has the advantage of not popping up a window.
这篇关于javascript中的下载文件在Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文