Principle: window.open () method, open a new blank page, and then paste the code in the text box through the DOM operation, write to the new code page,
Re-use the function of document.write (written in before the other all deleted, and written in the HTML code can be parsed.) ) to achieve the desired effect.
Window.Open opens a new page is also a browser object, also has document.write this method;.
1 <!DOCTYPE HTML>2 <HTML>3 <!--4 [email protected]5 Time: 2017-04-076 Description: Run the code gadget online7 -8 <Head>9 <MetaCharSet= "UTF-8">Ten <title>Run code Online</title> One <Metaname= "Author"content= "gjf_xing.org1^"/> A <Metaname= "Description"content= "gadget to run code online"/> - <Metaname= "Keywords"content= "Gadget, code run, run code, open method, New page, online debug"/> - </Head> the <Body> - <textareaname=""rows= "+"cols= "a"ID= "txt"></textarea> - <BR/> - <inputtype= "button"name=""ID= "BTN"value= "Run Code" /> + </Body> - <Scripttype= "Text/javascript"> + window.onload= function(){ A varOtxt=document.getElementById ("txt"), at obtn=document.getElementById ("btn"); - Obtn.onclick= function(){ - varW=window.open ("About:blank","_blank"); - W.document.write (otxt.value); - }; - }; in </Script> - </HTML>
js-Running Code Widgets online