diff --git a/js/privatebin.js b/js/privatebin.js index 933c97d..9a8e7a3 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1925,7 +1925,37 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { { var imagePrefix = 'data:image/'; - $attachmentLink.attr('href', attachmentData); + // IE does not support setting a data URI on an a element + // Convert dataURI to a Blob and use msSaveBlob to download + if (window.Blob && navigator.msSaveBlob) { + $attachmentLink.off('click').on('click', function () { + // data URI format: data:[][;base64], + + // position in data URI string of where data begins + var base64Start = attachmentData.indexOf(',') + 1; + // position in data URI string of where mediaType ends + var mediaTypeEnd = attachmentData.indexOf(';'); + + // extract mediaType + var mediaType = attachmentData.substring(5, mediaTypeEnd); + // extract data and convert to binary + var decodedData = Base64.atob(attachmentData.substring(base64Start)); + + // Transform into a Blob + var decodedDataLength = decodedData.length; + var buf = new Uint8Array(decodedDataLength); + + for (var i = 0; i < decodedDataLength; i++) { + buf[i] = decodedData.charCodeAt(i); + } + + var blob = new window.Blob([ buf ], { type: mediaType }); + navigator.msSaveBlob(blob, fileName); + }); + } else { + $attachmentLink.attr('href', attachmentData); + } + if (typeof fileName !== 'undefined') { $attachmentLink.attr('download', fileName); } @@ -1971,6 +2001,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { me.hideAttachmentPreview(); $attachmentLink.prop('href', ''); $attachmentLink.prop('download', ''); + $attachmentLink.off('click'); $attachmentPreview.html(''); }; diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index b197179..909d53b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 5c54bb7..8128e0c 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): - +