ASP implementation of the Code "run Code" "Copy Code" "Save Code" function Source _ Application techniques

Source: Internet
Author: User
See a lot of people need, put it out, good things to share with everyone.
Copy Code code 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= Run code onclick=runcode (RunCode "&i&") ><input type=button class=input-code value= Replication Code onclick= Copycode (RunCode "&i&") ><input Type=button class=input-code value= Save Code Onclick=savecode (RunCode "& i& ") ><span class=code-tishi> Hint: You can modify some of the 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 use method is also very simple:

You need to use the "Run Code" feature when you publish an article, mainly plus

[Code] [/code]
Like what:

Copy Code code as follows:

[Code]
<script type= "Text/javascript" >
Alert ("Simple Bar");
</script>
[/code]
It should be noted that the page to be displayed is to enter the following javascript:

Copy Code code as follows:

function RunCode (obj) {
var winname = window.open ("," _blank ",");
Winname.document.open (' text/html ', ' replace ');
Winname.opener = null
Winname.document.writeln (Obj.value);
Winname.document.close ();
}

function Copycode (obj) {
var rng = Document.body.createTextRange ();
Rng.movetoelementtext (obj);
Rng.scrollintoview ();
Rng.select ();
Rng.execcommand ("Copy");
Rng.collapse (FALSE);
}
function Savecode (obj) {
var winname = window.open (', ' _blank ', ' top=10000 ');
Winname.document.open (' text/html ', ' replace ');
Winname.document.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.