Motivation: https://stackoverflow.com/questions/28120689/create-self-modifying-html-page-on-box
Error: erasing lines, formatting html , js generated by the initial edited, saved html , js
eg,
a) if "saveFile.html" is open in the local browser;
b) enter "abc" in textarea ;
c) click save file ;
d) click Save in the save file dialog box;
e) file-*[date according to universal time].html saved to disk;
f) open file-*[date according to universal time].html in a browser;
g) enter "def" in textarea ;
h) repeat d), e), f);
i) Error: the result in the second file-*[date according to universal time].html displays textarea containing the text content "abc def"; button does not appear in html :
// at rendered `html` from second `file-*[date according to universal time].html` // `textarea` containing "abc def" displayed here , // `button` _not_ displayed ; following string displayed following `textarea`: ');"console.log(clone);var file = new Blob([clone], {'type':'text/html'});a.href = URL.createObjectURL(file);a.download = 'file-' + new Date().getTime() + '.html';a.click();};
generated on line 26, "saveFile.html"
+ "var clone = '<!doctype html>'+ document.documentElement.outerHTML.replace(/<textarea>.*<.+textarea>/, '<textarea>'+document.getElementsByTagName('textarea')[0].value+'<\/textarea>');"
"saveFile.html" v 1.0.0
html js
<!doctype html> <html> <head> </head> <body> <textarea> </textarea> <button>save file</button> <script type="text/javascript"> var saveFile = document.getElementsByTagName("button")[0]; var input = document.getElementsByTagName("textarea")[0]; var a = document.createElement("a"); saveFile.onclick = function(e) { var clone = ["<!doctype html><head></head><body><textarea>" + input.value + "</textarea>" + "<button>save file</button>" + "<script type='text/javascript'>" + "var saveFile = document.getElementsByTagName('button')[0];" + "var input = document.getElementsByTagName('textarea')[0];" + "var a = document.createElement('a');" + "saveFile.onclick = function(e) {" + "var clone = '<!doctype html>'+ document.documentElement.outerHTML.replace(/<textarea>.*<.+textarea>/, '<textarea>'+document.getElementsByTagName('textarea')[0].value+'<\/textarea>');" + "console.log(clone);" + "var file = new Blob([clone], {'type':'text/html'});" + "a.href = URL.createObjectURL(file);" + "a.download = 'file-' + new Date().getTime() + '.html';" + "a.click();" + "};" + "</scr"+"ipt>" + "</body>" + "</html>"]; var file = new Blob([clone], {"type":"text/html"}); a.href = URL.createObjectURL(file); a.download = "file-" + new Date().getTime() + ".html"; a.click(); }; </script> </body> </html>