The principle code is as follows
| The code is as follows |
Copy Code |
<script> function Preview () { var testwin=open ('); TestWin.document.write (Code.value); } </script> |
The code above is to create a new window, and then put the characters in the specified container on the page to run.
Example
| code is as follows |
copy code |
| <!doctype html> <meta charset= "Utf-8"/> <script> window.onload = function () { var otxt = document.getElementById (' Codetext ') ; var obtn = document.getElementById (' btn '); Obtn.onclick = function () { var onewwin = window.open (' About:blank ', ' _blank ');//Open blank page in new Window (BOM) Onewwin . document.write (Otxt.value); Write the value of the input box in a blank page } </script> <body> <textarea id= "Codetext" rows= "Ten" cols= "></textarea><br"/> <input id= "btn" type= "button" value= "Run"/> <!-- Only open windows can be closed under FF </body> |
Code Analysis
window.open (' About:blank ', ' _blank '); is to tell us to open a new window without replacing the current window OH
ONewWin.document.write (Otxt.value); Write the value of an input box in a blank page
is to get the contents of our text box and we output it to the new window we created to make it possible for the page to run.