RunCode (test code) function on the webpage

Source: Internet
Author: User
In most forums or blogs, you can see a piece of code in the author's or comments and perform online testing. the code for implementing this function is as follows: [javascript] & lt ;! DOCTYPEhtmlPUBLIC & quot;-// W3C // DTDXHTML1.0Transitional // EN & quot ;...

In most forums or blogs, you can see a piece of code in the author's or comments and perform online testing.

The code for implementing this function is as follows:


[Javascript]
 
 
 
 
 
Run Code 
 
Script
Function runCode (textId ){
Var code = document. getElementById (textId). value;
Var newWindow = window. open ();
NewWindow. opener = null; // do not perform any operation on the Window that creates the Window (newWindow.
Newmediaworkflow Doc ument. write (code );
Newclientdoc ument. close (); // close the file stream opened by the open () method.
};
Function copyCode (textId ){
If (window. clipboardData) {// judge the browser. Currently, only Internet Explorer is supported.
Var otext = document. getElementById (textId). value;
Window. clipboardData. setData ('text', otext );
Alert ('copied successfully! ');
} Else {
Alert ("your browser does not support this function. Please manually select text to copy it! ");
}
};
Script
 
 
 

<B> Hi, This is my website! </B> </textarea "> http://maplejan.com/"> website! </B> 

 
 
 

 
 





Run Code

Script
Function runCode (textId ){
Var code = document. getElementById (textId). value;
Var newWindow = window. open ();
NewWindow. opener = null; // do not perform any operation on the Window that creates the Window (newWindow.
Newmediaworkflow Doc ument. write (code );
Newclientdoc ument. close (); // close the file stream opened by the open () method.
};
Function copyCode (textId ){
If (window. clipboardData) {// judge the browser. Currently, only Internet Explorer is supported.
Var otext = document. getElementById (textId). value;
Window. clipboardData. setData ('text', otext );
Alert ('copied successfully! ');
} Else {
Alert ("your browser does not support this function. Please manually select text to copy it! ");
}
};
Script



 
<B> Hi, This is my website! </B>




 


Demo


Excerpt from jian sheng's code Memorandum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.