Skip to content

Commit 89994f7

Browse files
committed
image download fix for IE
1 parent 4085e7a commit 89994f7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/components/Plot.jsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,26 @@ class Plot extends React.Component {
456456
return;
457457
}
458458

459+
var canvas = imageRef.current.canvas._canvas;
459460

460-
var dataURL = imageRef.current.toDataURL({ pixelRatio: 3 });
461+
if (canvas.msToBlob && navigator.msSaveBlob) {
462+
// for IE
463+
var blob = canvas.msToBlob();
464+
window.navigator.msSaveBlob(blob, plotName);
465+
466+
} else {
467+
// other browsers
468+
469+
var dataURL = imageRef.current.toDataURL({ pixelRatio: 3 });
470+
var link = document.createElement('a');
471+
link.download = plotName;
472+
link.href = dataURL;
473+
document.body.appendChild(link);
474+
link.click();
475+
document.body.removeChild(link);
476+
link.remove();
477+
}
461478

462-
var link = document.createElement('a');
463-
link.download = plotName;
464-
link.href = dataURL;
465-
document.body.appendChild(link);
466-
link.click();
467-
document.body.removeChild(link);
468-
link.remove();
469479
}
470480

471481
_filterDomains(plotData, pdbs) {
@@ -483,4 +493,4 @@ class Plot extends React.Component {
483493
}
484494
}
485495

486-
export default Plot;
496+
export default Plot;

0 commit comments

Comments
 (0)