It solves the problem of direct copying in Firefox, but the Execution Code contains the tag that references the JS file. In Firefox, the script cannot be downloaded and cannot be correctly executed. You can learn from them!
- <HTML>
- <Head>
- <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
- <Title> RUN copy and save </title>
- </Head>
- <Body>
- <Script language = "JavaScript" type = "text/JavaScript">
- // Run the text domain code
- Function runcode (ID ){
- Cod = Document. getelementbyid (ID );
- VaR codcode = cod. value;
- If (code! = ""){
- VaR newwin = Window. Open ('','', ''); // open a window and assign it to the variable newwin.
- Newwin.doc ument. Open ('text/html ', 'replace ');
- Newwin. Opener = NULL // prevents code from modifying the Forum Page
- Newwin.doc ument. Write (CODE); // write the code to this open window to implement the Code running function.
- Newwin.doc ument. Close ();
- }
- }
- Function copycode (ID)
- {
- VaR text2copy = Document. getelementbyid (ID). value;
- If (window. clipboardData)
- {
- Window. clipboardData. setdata ("text", text2copy );
- }
- Else
- {
- VaR flashcopier = 'flashcopier ';
- If (! Document. getelementbyid (flashcopier ))
- {
- VaR divholder = Document. createelement ('div ');
- Divholder. ID = flashcopier;
- Document. Body. appendchild (divholder );
- }
- Document. getelementbyid (flashcopier). innerhtml = '';
- VaR divinfo = '<embed src = "_clipboard.swf" flashvars = "Clipboard =' + escape (text2copy) + '"width =" 0 "Height =" 0 "type =" application/X-Shockwave-flash "> </embed>'; // The key here
- Document. getelementbyid (flashcopier). innerhtml = divinfo;
- }
- Return true;
- }
- Function savecode (ID ){
- VaR tcode = Document. getelementbyid (ID). value;
- VaR winname = Window. Open ('', '_ blank', 'top = 10000 ');
- Winname.doc ument. Open ('text/html ', 'replace ');
- Winname.doc ument. writeln (tcode );
- Winname.document.execcommand('saveas', '', 'code.html ');
- Winname. Close ();
- }
- Function createmap (){
- VaR MAP2 = new ltmaps ("MAP2 ");
- Map2.centerandzoom (New ltpoint (41540969,3994940), 6 );
- VaR points = new array ();
- Points. Push (New ltpoint (11629376,399 5776 ));
- Points. Push (New ltpoint (11642688,398 8608 ));
- Points. Push (New ltpoint (11641152,399 2640 ));
- VaR polyline = new ltpolyline (points );
- Map2.addoverlay (polyline );
- }
- </SCRIPT>
- <Textarea name = "textarea" Cols = "60" rows = "10" id = "rn01">
- <HTML xmlns: V = "urn: Schemas-Microsoft-com: VML">
- <Head>
- <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
- <Meta name = "keywords" content = ""/>
- <Title> Map </title>
- <Style type = "text/CSS"> V/: * {behavior: URL (# default # VML);} </style>
- <SCRIPT type = "text/JavaScript" src = "http://api.51ditu.com/js/maps.js"> </SCRIPT>
- <SCRIPT type = "text/JavaScript">
- Function createmap (){
- VaR MAP2 = new ltmaps ("MAP2 ");
- Map2.centerandzoom (New ltpoint (41540969,3994940), 6 );
- VaR points = new array ();
- Points. Push (New ltpoint (11629376,399 5776 ));
- Points. Push (New ltpoint (11642688,398 8608 ));
- Points. Push (New ltpoint (11641152,399 2640 ));
- VaR polyline = new ltpolyline (points );
- Map2.addoverlay (polyline );
- }
- </SCRIPT>
- </Head>
- <Body onload = "createmap ()">
- <Div id = "MAP2" style = "width: 400px; Height: 300px;"> </div>
- </Body>
- </Html>
- </Textarea>
- <Br> <input onclick = "runcode ('rn01')" type = "button" value = "run code" style = "cursor: Hand">
- <Input type = button value = "copy" onclick = "copycode ('rn01')">
- <Input type = button value = "save" onclick = "savecode ('rn01')">
- <Br/>
- </Body>
- </Html>