Run the code on the webpage, save it as, and copy the js Code of the Code.

Source: Internet
Author: User

We can see some js special effects code on many special effects websites. You can click Save or run it directly to view the effect. Let's take a look at the implementation code of this effect.

The Code is as follows: Copy code

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Head>

<Body>
<Script type = "text/javascript">
// JavaScript Document

// Run the code
Function doRunCode (cod1 ){
Cod = document. getElementById (cod1)
Var code = cod. value;
If (code! = ""){
Var newwin = window. open ('','','');
Newwin. opener = null
Newwin.doc ument. write (code );
Newwin.doc ument. close ();
}
}
// Copy the code
Function doCopyCode (ID ){
If (document. all ){
TextRange = document. getElementById (ID). createTextRange ();
TextRange.exe cCommand ("Copy ");
}
Else {
// Alert ("this function is only valid on IE ");
CopyToClipboard (document. getElementById (ID). value );
}
}
// Save as code
Function doSaveCode (cod1 ){
Cod = document. getElementById (cod1)
Var code = cod. value;
If (code! = ""){
Var winname = window. open ('', '_ blank', 'top = 10000 ');
Winname.doc ument. open ('text/html ', 'replace ');
Winname.doc ument. write (code );
Winname.document.execcommand('saveas', '', 'code.htm ');
Winname. close ();
}
}
Function copyToClipboard (txt ){
If (window. clipboardData ){
Window. clipboardData. clearData ();
Window. clipboardData. setData ("Text", txt );
} Else if (navigator. userAgent. indexOf ("Opera ")! =-1 ){
Window. location = txt;
} Else if (window. netscape ){
Try {
Netscape. security. PrivilegeManager. enablePrivilege ("UniversalXPConnect ");
} Catch (e ){
Alert ("rejected by the browser! N enter 'about: config' in the address bar of the browser, press ENTER n, and set 'signed. applets. codebase_principal_support 'to 'true '");
}
Var clip = Components. classes ['@ mozilla.org/widget/clipboard=1'mirror.createinstance (Components. interfaces. nsIClipboard );
If (! Clip)
Return;
Var trans = Components. classes ['@ mozilla.org/widget/transferable00001').createinstance (Components. interfaces. nsITransferable );
If (! Trans)
Return;
Trans. addDataFlavor ('text/unicode ');
Var str = new Object ();
Var len = new Object ();
Var str = Components. classes ["@ mozilla.org/supports-string1_1"]. createInstance (Components. interfaces. nsISupportsString );
Var copytext = txt;
Str. data = copytext;
Trans. setTransferData ("text/unicode", str, copytext. length * 2 );
Var clipid = Components. interfaces. nsIClipboard;
If (! Clip)
Return false;
Clip. setData (trans, null, clipid. kGlobalClipboard );
}
}

</Script>
<Div class = "UBBContainer">
<Div class = "UBBTitle"> The following is the program code </div>
<Div class = "UBBContent">
<Textarea class = "UBBText" id = "CodeText62670" rows = "8"> here is the html code to be run. </textarea>
<Br>
<Input type = "button" value = "Running code" onclick = "doRunCode ('codetext62670')">
<Input type = "button" value = "Copy code" onclick = "doCopyCode ('codetext62670')">
<Input type = "button" value = "other code" onclick = "doSaveCode ('codetext62670')">
<Br>
[Ctrl + A select all tips: you can modify some code and then press run] </div>
</Div>
</Body>
</Html>

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.