方法一:
打开新窗口,替换成下载界面
function doSave(obj) {
obj=('obj');//obj是需要下载的内容
if (isIE()){//IE浏览器保存文本框内容
var winname = ('', '_blank', 'top=10000');
('text/html', 'replace');
();
('saveas','','');//可改为自定义文件名
();}
}
function isIE()//判断浏览器类型
{
if(!! || "ActiveXObject" in window)
return true;
else
return false;
}
参考:https:///article/?tdsourcetag=s_pctim_aiomsg
方法二:
通过blob对象下载
=function(obj,fileName) {
if (isIE()){//IE浏览器保存文本框内容
var filename = fileName + ".txt";
var type = "text/plain; charset=UTF-8";
var blob = typeof File === 'function'
? new File([obj], filename, { type: type })
: new Blob([obj], { type: type });
if (typeof !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
(blob, filename);
} else {
var URL = || ;
var downloadUrl = (blob);
if (filename) {
// use HTML5 a[download] attribute to specify filename
var a = ("a");
// safari doesn't support this yet
if (typeof === 'undefined') {
= downloadUrl;
} else {
= downloadUrl;
= filename;
(a);
();
}
} else {
= downloadUrl;
}
}
}
}
方法三:
function downloadFile(url){
//var url = CONTEXTPATH + "/cim/favorite/plotlayer/download?&filetype=" + filetype;
var elemIF = ("iframe");
= url;
= "none";
(elemIF);
}
(url是下载的内容)
(此方法同样适用于xls下载,url返回xls表格则下载xls)
参考:/lishuangzhe7047/article/details/43560447