//onclick方法调用次方法
//这里传入文件地址
function download_pic(src) {
var codeurl = src;
if (browserIsIe()) {
//假如是ie浏览器
DownLoadReportIMG(codeurl);
} else {
//非Ie,可尝试a标签download 属性方法
$("#download").attr('href', codeurl);
$("#download").attr('download', codeurl);
document.getElementById("download").click();
}
}
function DownLoadReportIMG(imgPathURL) {
//如果隐藏IFRAME不存在,则添加
//ie下,如无 iframe 标签,先添加一个,否者会报错
if (!document.getElementById("IframeReportImg"))
$('<iframe style="display:none;" id="IframeReportImg" name="IframeReportImg" onload="DoSaveAsIMG();" width="0" height="0" src="about:blank"></iframe>').appendTo("body");
if (document.all.IframeReportImg.src != imgPathURL) {
//加载图片
document.all.IframeReportImg.src = imgPathURL;
}
else {
//图片直接另存为
DoSaveAsIMG();
}
}
function DoSaveAsIMG() {
if (document.all.IframeReportImg.src != "about:blank")
window.frames["IframeReportImg"].document.execCommand("SaveAs");
}
//判断是否为ie浏览器
function browserIsIe() {
if (!!window.ActiveXObject || "ActiveXObject" in window)
return true;
else
return false;
}