Custom HTML code runtime box
To set the HTML runtime box, prepare the following materials:
1. textarea
<Textarea style = "width: 450; Height: 300" id = "thecode" Title = "double-click the Running code" ondblclick = "runcode ('thecode '); "> put the running HTML code here. </Textarea> <br/> <input onclick = "runcode ('thecode ') "value =" run code "type =" button "> <input onclick =" docopy ('thecode ') "value =" Copy code "type =" button "> <input onclick =" dosave ('thecode', 'test ') "value =" Save code "type =" button ">
2. Three buttons
<SCRIPT type = "text/JavaScript"> // run the code function runcode (OBJ) {var winname = Window. open (''," _ blank ",''); var content = document. getelementbyid (OBJ ). value; winname.doc ument. open ('text/html ', 'replace'); winname. opener = NULL winname.doc ument. writeln (content); winname.doc ument. close () ;}// copy the code function docopy (OBJ) {var codeobj = document. getelementbyid (OBJ); clipboardData. setdata ('text', codeobj. innertext); alert ('copied Code');} // save as file function dosave (OBJ, filename) {var win = Window. open ('', '_ blank', 'top = 10000 '); var code = document. getelementbyid (OBJ ). innertext; win. opener = NULL; win.doc ument. write (CODE); win.document.exe ccommand ('saveas', true, filename); win. close () ;}</SCRIPT>