W3C.US

  • Increase font size
  • Default font size
  • Decrease font size
Home Experience Javascript Run input javascript code in new browser

Run input javascript code in new browser

E-mail Print PDF

We have noticed that some javascript technological site provided the dynamical js running environment. The code is shown in a textarea, and you can click the RUN button to run it. And also you can change the code to test it.

Just like below(runinput.html):

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Run Input Javascript Code</title>
</head>

<body>
<script language="javascript">
function runcode()  {
     cod=document.getElementById("jsta");
     var code=cod.value;
     if (code!=""){
          var newwin=window.open('','','');  //open a new window
          newwin.opener = null                  //new window cannot call its parent         
          newwin.document.write(code);    //write the code to new window         
          newwin.document.close();           //close the document   
    }
}
</script>

<p>
  <textarea id="jsta" cols="80" rows="20"></textarea>
</p>
<p>
  <input type="button" name="runcode" value="runcode" onclick="runcode();">
</p>
</body>
</html>

 Open the html file in IE or Firefox, input below code into the textarea:

<script language="javascript">

document.write("test");

</script>

And click the RUN button, a new window should be open, and the js write the word "test" on it.

 

Now, I merged the js code to the template, so the article can show and run user-input javascript:

http://w3c.us/experience-menu/37-javascript-exp/52-javascript-run-on-joomla-pages

 

 

Last Updated on Saturday, 02 May 2009 02:12