通过按钮点击IE浏览器下载Jqplot图像 [英] Jqplot image download by a button click in IE
问题描述
我有jqplot,我想下载一次按钮作为jpg或png。我可以使用
I have jqplot and I want to download it once click a button as a jpg or png. I can do it using
$('#chartdiv').jqplotSaveImage();
(chartdiv是带有情节的div)
(chartdiv is the div with plot)
它仅适用于chrome和firefox。在IE浏览器中它无效。我在IE 11中试过。
It is working in chrome and firefox only. In IE it is not working.I tried in IE 11.
我在chrome中有另一个问题,下载的图像文件名是'download'而在firefox中它是一些带有.part扩展名的有线名称(例如: - ka8ShgKH.part)。有没有办法将情节标题作为下载文件名?
And I have another problem in chrome the downloaded image file name is 'download' and in firefox it is some wired name with .part extension (ex :- ka8ShgKH.part). Is there a way to put plot title as the download file name ?
谢谢。
$("#btnSaveImg").on("click", LoadImage);
LoadImage = function(){
$('#chartdiv').jqplotSaveImage();
}
编辑
jqplotsaveimage函数
EDIT jqplotsaveimage function
$.fn.jqplotSaveImage = function() {
var imgData = $(this).jqplotToImageStr({});
if (imgData) {
window.location.href = imgData.replace("image/png", "image/octet-stream");
}
};
推荐答案
我正在使用jqPlot我遇到了使用以上在IE中,即使它在Chrome中有效,我也无法命名下载的图像。
I'm using jqPlot and I had issues using the above in IE and even if it worked in Chrome I could not name the downloaded image.
我发现这个案例强制下载base64图像和 http:/ /danml.com/download.html 。这在IE和Chrome的更高版本中都有效,您可以使用自己的文件名保存图像。 download.js不仅可用于图像。
I found this case force download base64 image and the http://danml.com/download.html . That's working both in later versions of IE and Chrome and you can save the image with your own filename. The download.js can be used for more than just images.
//include the downoad.js file from http://danml.com/download.html
<button id="dwnl-chart-1" onClick="$.fn.jqplotSaveImage('chart-1', 'chart_name">Download as image</button>
$.fn.jqplotSaveImage = function(id, filename) {
var imgData = $('#'+id+'-parent').jqplotToImageStr({});
if (imgData) {
download(imgData, filename+'.png', "image/png");
}
};
这篇关于通过按钮点击IE浏览器下载Jqplot图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!