javascript - How do I make a save button that will make a .html file? -
i making code tester , wondering how make save button code tester. intent make save .html file in "u" directory on site shows them link saved code. example: http://jswebsite.co.nf/u/1.html. here code:
<iframe src="menu-bar.html" height="45" width="1300" align="right" scrolling="no" frameborder="0"></iframe> <br /> <br /> <br /> <!-- code tester starts --> <div class="center-page"> <!-- code tester scripts starts --> <script src="http://jswebsite.co.nf/code-tester-javascript.min.js"></script> <!-- code tester scripts end --> <p>if press ctrl + enter, code open in new tab. if press "test html code" button, code open in new window if using chrome browser. <br />please resize code box if needed.</p> <p style="font-size:23px; color: white;">code tester html:</p> <form name="tester"> <textarea rows="20" cols="120" name="code-box" wrap="physical" id="codebox" spellcheck="false"></textarea> <br /> <input type="button" value="test html code" onclick="preview()"> <input value="clear html code" type="reset"> <button onclick="togetherjs(this); return false;">collaborate</button> </form> </div> <!-- code tester ends -->
you can use function:
function save(filename, html) { var el = document.createelement('a'); el.setattribute('href', 'data:text/html;charset=utf-8,' + encodeuricomponent(html)); el.setattribute('download', filename); el.style.display = 'none'; document.body.appendchild(el); el.click(); document.body.removechild(el); }
usage:
save('test.html', '<html></html>');
Comments
Post a Comment