From dec7870eeb4822a20a06dbe8a09f80050a8d2b19 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 19 Sep 2013 10:50:14 +0100 Subject: [PATCH] Update HTML5 saver to use current filename where possible Most browsers still ignore the specified filename, sadly. --- core/modules/savers/download.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/modules/savers/download.js b/core/modules/savers/download.js index 3f2e9c08f..623285561 100644 --- a/core/modules/savers/download.js +++ b/core/modules/savers/download.js @@ -19,11 +19,17 @@ var DownloadSaver = function(wiki) { }; DownloadSaver.prototype.save = function(text) { + // Get the current filename + var filename = "tiddlywiki.html", + p = document.location.pathname.lastIndexOf("/"); + if(p !== -1) { + filename = document.location.pathname.substr(p+1); + } // Set up the link var link = document.createElement("a"); link.setAttribute("target","_blank"); link.setAttribute("href","data:text/html," + encodeURIComponent(text)); - link.setAttribute("download","tiddlywiki.html"); + link.setAttribute("download",filename); document.body.appendChild(link); link.click(); document.body.removeChild(link);