JS implementation Run, select all, copy, save code Program

Source: Internet
Author: User

HTML code

The code is as follows Copy Code

<textarea name= "Content" id= "Content" >
Here's where you want to run js,html code
</textarea>

<input type= "button" Name= "Submit" value= Run Code "onclick=" RunCode (' content ')/>
<input type= "button" Name= "Submit3" value= "All selected Code" onclick= "$ (' content '). Select ();"/>
<input type= "button" Name= "SUBMIT4" value= "Copy Code" onclick= "ocopy (' content ')/>
<input type= "button" Name= "Submit2" value= "Save Code" onclick= "Savecode (' content ')/>

JS Code

The code is as follows Copy Code

<script>
var lang = new Array ();
var useragent = Navigator.userAgent.toLowerCase ();
var Is_opera = useragent.indexof (' opera ')!=-1 && opera.version ();
var Is_moz = (Navigator.product = = ' Gecko ') && useragent.substr (Useragent.indexof (' Firefox ') + 8, 3);
var Is_ie = (useragent.indexof (' MSIE ')!=-1 &&!is_opera) && useragent.substr (' Useragent.indexof ' ) + 5, 3);

Array.prototype.push = function (value) {
This[this.length] = value;
return this.length;
}
function $ (objname) {return document.getElementById (objname);}
function RunCode (objname) {
var winname = window.open ("," _blank ",");
var obj = $ (objname);
Winname.document.open (' text/html ', ' replace ');
Winname.opener = NULL//Prevent code to talk about page modification
Winname.document.write (Obj.value);
Winname.document.close ();
}
function Savecode (objname) {
var winname = window.open (', ' _blank ', ' top=10000 ');
Winname.document.open (' text/html ', ' replace ');
var obj = $ (objname);
Winname.document.write (Obj.value);
Winname.document.execCommand (' SaveAs ', ', ', ' code.htm ');
Winname.close ();
}

function Ocopy (objname) {
var obj = $ (objname);
Obj.select ();
Js=obj.createtextrange ();
Js.execcommand ("Copy");
Alert ("Www.111cn.net hint: The code has been copied successfully!") ");
}

</script>

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.