From 23547b19674fed733245fc9bec0facb9af855e72 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Sun, 19 Oct 2014 11:19:19 +0300 Subject: adding proper Save As (with non random filename); MIT licensed Actually seems that the proper way to save nowadays is the [download] (https://html.spec.whatwg.org/multipage/semantics.html#attr-hyperlink-download) attribute of a 'a' element, but that's also supported by the added [FileSaver.js] (external/scripts/FileSaver.js) --- scripts/buttons.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/buttons.js b/scripts/buttons.js index 69f0a6c7..1543b4cc 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -13,8 +13,10 @@ $('.save').click(function(){ $('.saveToFile').click(function() { var json = graph.save_to_json(); - console.log(json); - location.href = 'data:text/json;base64,' + window.btoa(json); + var filename = 'graph.json'; + var blob = new Blob([json], {type: 'application/json'}); + console.log('saving ' + json.length + ' bytes to ' + filename); + saveAs(blob, filename); }); var really_load = function() { -- cgit v1.3.1