How to load current innerHTML document as a file?

Is there a way to load the current innerHTML document into a file programmatically ?

I made the following attempt without success. It downloads the current source of the document, however this is not what I am looking for since I want to save any modifications to the documents after loading .

  var save = document.createElement('a'); save.href = "my location href.attr"; save.target = '_blank'; save.download = fileName || 'unknown'; var event = document.createEvent('Event'); event.initEvent('click', true, true); save.dispatchEvent(event); 
+8
javascript download
source share
1 answer

Perhaps something like this? However, it's probably not a very cross browser, but it works in Chrome.

 function downloadCurrentDocument() { var base64doc = btoa(unescape(encodeURIComponent(document.documentElement.innerHTML))), a = document.createElement('a'), e = new MouseEvent('click'); a.download = 'doc.html'; a.href = 'data:text/html;base64,' + base64doc; a.dispatchEvent(e); } downloadCurrentDocument(); 
+7
source share

All Articles