fix file downloads out of iframes like nextcloud

This commit is contained in:
cracker0dks 2019-04-05 14:56:09 +02:00
parent fac73b84ac
commit b839fd66fa

View File

@ -123,25 +123,33 @@ $(document).ready(function () {
// save image to png // save image to png
$("#saveAsImageBtn").click(function () { $("#saveAsImageBtn").click(function () {
var imgData = whiteboard.getImageDataBase64(); var imgData = whiteboard.getImageDataBase64();
var w = window.open('about:blank'); //Firefox will not allow downloads without extra window
setTimeout(function () { //FireFox seems to require a setTimeout for this to work.
var a = document.createElement('a'); var a = document.createElement('a');
a.href = imgData; a.href = imgData;
a.download = 'whiteboard.png'; a.download = 'whiteboard.png';
document.body.appendChild(a); w.document.body.appendChild(a);
a.click(); a.click();
document.body.removeChild(a); w.document.body.removeChild(a);
setTimeout(function () { w.close(); }, 100);
}, 0);
}); });
// save image to json containing steps // save image to json containing steps
$("#saveAsJSONBtn").click(function () { $("#saveAsJSONBtn").click(function () {
var imgData = whiteboard.getImageDataJson(); var imgData = whiteboard.getImageDataJson();
var a = window.document.createElement('a');
var w = window.open('about:blank'); //Firefox will not allow downloads without extra window
setTimeout(function () { //FireFox seems to require a setTimeout for this to work.
var a = document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([imgData], { type: 'text/json' })); a.href = window.URL.createObjectURL(new Blob([imgData], { type: 'text/json' }));
a.download = 'whiteboard.json'; a.download = 'whiteboard.json';
// Append anchor to body. w.document.body.appendChild(a);
document.body.appendChild(a);
a.click(); a.click();
// Remove anchor from body w.document.body.removeChild(a);
document.body.removeChild(a); setTimeout(function () { w.close(); }, 100);
}, 0);
}); });
// upload json containing steps // upload json containing steps