ASP implements the "run code", "Copy code", and "Save code" function source code.

Source: Internet
Author: User

Let's see a lot of people who need it. Let's share some good things. CopyCode The Code is as follows: function content_code (STR)
Dim ary_string, I, n, n_pos
Ary_string = Split (STR, "[Code]")
N = ubound (ary_string)
If n <1 then
Content_code = Str
Exit Function
End if
For I = 1 to n
N_pos = instr (ary_string (I), "[/Code]")
If n_pos> 0 then
Ary_string (I) = "<br/> <textarea class = gocode id = runcode" & I & "name = runcode" & I & ">" & server. htmlencode (left (ary_string (I), n_pos-1 )) & "</textarea> <br/> <input type = button class = input-code value = Running code onclick = runcode (runcode" & I & ")> <input type = button class = input-code value = copy code onclick = copycode (runcode "& I &")> <input type = button class = input-code value = save code onclick = savecode (runcode "& I &")> <SPAN class = code-tishi> prompt: you can modify some code before running </span> <br/> "&_
Right (ary_string (I), Len (ary_string (I)-n_pos-6)
Else
Ary_string (I) = "[Code]" & ary_string (I)
End if
Next
Content_code = join (ary_string ,"")
End Function

The usage is also simple:

PostArticleYou must use the "run code" function.

[Code] [/Code]
For example:

Copy code The Code is as follows: [Code]
<SCRIPT type = "text/JavaScript">
Alert ("simple ");
</SCRIPT>
[/Code]

Note that you need to enter the following JavaScript on the displayed page:

Copy code The Code is as follows: function runcode (OBJ ){
VaR winname = Window. Open (''," _ blank ",'');
Winname.doc ument. Open ('text/html ', 'replace ');
Winname. Opener = NULL
Winname.doc ument. writeln (obj. value );
Winname.doc ument. Close ();
}

Function copycode (OBJ ){
VaR RNG = Document. Body. createTextRange ();
RNG. movetoelementtext (OBJ );
RNG. scrollintoview ();
RNG. Select ();
Rng.exe ccommand ("copy ");
RNG. Collapse (false );
}
Function savecode (OBJ ){
VaR winname = Window. Open ('', '_ blank', 'top = 10000 ');
Winname.doc ument. Open ('text/html ', 'replace ');
Winname.doc ument. Write (obj. value );
Winname.document.execcommand('saveas', '', 'code.htm ');
Winname. Close ();
}

Related Article

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.