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
1 changed files with 32 additions and 24 deletions

View File

@ -123,25 +123,33 @@ $(document).ready(function () {
// save image to png
$("#saveAsImageBtn").click(function () {
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');
a.href = imgData;
a.download = 'whiteboard.png';
document.body.appendChild(a);
w.document.body.appendChild(a);
a.click();
document.body.removeChild(a);
w.document.body.removeChild(a);
setTimeout(function () { w.close(); }, 100);
}, 0);
});
// save image to json containing steps
$("#saveAsJSONBtn").click(function () {
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.download = 'whiteboard.json';
// Append anchor to body.
document.body.appendChild(a);
w.document.body.appendChild(a);
a.click();
// Remove anchor from body
document.body.removeChild(a);
w.document.body.removeChild(a);
setTimeout(function () { w.close(); }, 100);
}, 0);
});
// upload json containing steps