From ffbec0f0660d823ab1ef3f63677062a562693128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bestian=20Tang=20=E5=A4=A7=E5=B7=B4?= Date: Tue, 14 May 2024 09:00:11 +0800 Subject: [PATCH] close #3 --- demo_de.html | 24 +++++++++++++++++++++--- demo_en.html | 24 +++++++++++++++++++++--- demo_zh-hant.html | 24 +++++++++++++++++++++--- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/demo_de.html b/demo_de.html index c8ecc01..a9cfe19 100644 --- a/demo_de.html +++ b/demo_de.html @@ -767,14 +767,32 @@ function saveWorkspaceToDownload() { var xml = Blockly.Xml.workspaceToDom(workspace); var xml_text = Blockly.Xml.domToText(xml); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(xml_text), 'webseite.blockly.xml'); + var blob = new Blob([xml_text], {type: "text/xml"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.blockly.xml'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } - document.getElementById("saveButton").onclick = saveWorkspaceToDownload; function saveHtmlToDownload() { var code = HtmlGenerator.workspaceToCode(workspace); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(code), 'webseite.html'); + var blob = new Blob([code], {type: "text/html"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.html'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } + + document.getElementById("saveButton").onclick = saveWorkspaceToDownload; + document.getElementById("exportButton").onclick = saveHtmlToDownload; diff --git a/demo_en.html b/demo_en.html index 8237a8b..1a8cb9b 100644 --- a/demo_en.html +++ b/demo_en.html @@ -767,14 +767,32 @@ function saveWorkspaceToDownload() { var xml = Blockly.Xml.workspaceToDom(workspace); var xml_text = Blockly.Xml.domToText(xml); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(xml_text), 'webseite.blockly.xml'); + var blob = new Blob([xml_text], {type: "text/xml"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.blockly.xml'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } - document.getElementById("saveButton").onclick = saveWorkspaceToDownload; function saveHtmlToDownload() { var code = HtmlGenerator.workspaceToCode(workspace); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(code), 'webseite.html'); + var blob = new Blob([code], {type: "text/html"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.html'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } + + document.getElementById("saveButton").onclick = saveWorkspaceToDownload; + document.getElementById("exportButton").onclick = saveHtmlToDownload; diff --git a/demo_zh-hant.html b/demo_zh-hant.html index ec9df17..f9d7e4c 100644 --- a/demo_zh-hant.html +++ b/demo_zh-hant.html @@ -767,14 +767,32 @@ function saveWorkspaceToDownload() { var xml = Blockly.Xml.workspaceToDom(workspace); var xml_text = Blockly.Xml.domToText(xml); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(xml_text), 'webseite.blockly.xml'); + var blob = new Blob([xml_text], {type: "text/xml"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.blockly.xml'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } - document.getElementById("saveButton").onclick = saveWorkspaceToDownload; function saveHtmlToDownload() { var code = HtmlGenerator.workspaceToCode(workspace); - newWindow = window.open("data:application/octet-stream," + encodeURIComponent(code), 'webseite.html'); + var blob = new Blob([code], {type: "text/html"}); + var url = URL.createObjectURL(blob); + var a = document.createElement('a'); + a.href = url; + a.download = 'webseite.html'; // Specify the file name and extension + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } + + document.getElementById("saveButton").onclick = saveWorkspaceToDownload; + document.getElementById("exportButton").onclick = saveHtmlToDownload;