Discuz Forum NT version (2.6.1) Code Run Box implementation method

Source: Internet
Author: User
Tags copy modify version window root directory
To discuz! NT Forum plus script code to run the box method, you can directly in the forum using [html][/html] Insert Script effects method.

In doing Arisisi forum http://bbs.alixixi.com, you need to add the script to the post code. The relevant information is still difficult to find.

DZ Official forum does not provide the relevant script to run the box plug-in, the online public also only PHP version of the solution, and there are many problems.

Studied for half a day, finally found a solution, the final implementation of the results are as follows, you can support multiple script run box:

Full debugging and full support for all script debugging functions.

The method is as follows:

1, into the dz! NT Background >> posts >> posts related discuz! NT code, set the following figure and Save:

The replacement content is:

<textarea id= "{RANDOM}" rows= "cols=" >{1}</textarea><br><input Onclick=runex ("{RANDOM}" ) type= "button" value= "Run"/> <input onclick=docopy ("{RANDOM}") type= "button" value= "Copy"/> <input class= "su Bmit1 "Onclick=dosave (" {RANDOM} ") type=" button "value=" Save "/> Hint: You can modify the code before you run

2, modify the javascript/common.js of the Forum root directory, add the following script code at the end:

//Run code
Function RunEx (cod1)   {
  Cod=document.getelementbyid (cod1)
   var Code=cod.value;
   if (code!= "") {
    var newwin=window.open (', ', ', '); 
     Newwin.opener = null
    newwin.document.write (code); 
    Newwin.document.close ();
 }
}
//Copy code
Function DoCopy2 (ID) {
 if (document.all) {
   textRange = document.getelemen Tbyid (ID). createTextRange ();
   Textrange.execcommand ("Copy");
Alert (' Copy succeeded ');
 }
 else{
   alert (this feature can only be valid on IE)
 
}
//Copy code
Function docopy (obj) {
 var rng = Document.body.createTextRange ();
 rng.movetoelementtext (obj);
 rng.scrollintoview ();
 rng.select ();
 rng.execcommand ("Copy");
 rng.collapse (FALSE);
}

function Docopyurl ()
{
document.getElementById ("Copyurl"). Value=parent.location.href;
document.getElementById ("Copyurl"). Select ();
Document.execcommand ("copy");
Alert ("URL successfully copied to clipboard!") ")
}

Save Code
function Dosave (obj) {
var winname = window.open (', ' _blank ', ' top=10000 ');
Winname.document.open (' text/html ', ' replace ');
Winname.document.writeln (Obj.value);
Winname.document.execCommand (' SaveAs ', ', ', ' code.htm ');
Winname.close ();
}

You can use the two steps above to implement the Code run box effect, and finally add the test:

Through the above steps can be easily achieved.

This article for the Arisisi Web Development Home Original, reprint please indicate from Www.alixixi.com.



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.