Copy and save the Javascript script running window

Source: Internet
Author: User

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!

  1. <HTML>
  2. <Head>
  3. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  4. <Title> RUN copy and save </title>
  5. </Head>
  6. <Body>
  7. <Script language = "JavaScript" type = "text/JavaScript">
  8. // Run the text domain code
  9. Function runcode (ID ){
  10. Cod = Document. getelementbyid (ID );
  11. VaR codcode = cod. value;
  12. If (code! = ""){
  13. VaR newwin = Window. Open ('','', ''); // open a window and assign it to the variable newwin.
  14. Newwin.doc ument. Open ('text/html ', 'replace ');
  15. Newwin. Opener = NULL // prevents code from modifying the Forum Page
  16. Newwin.doc ument. Write (CODE); // write the code to this open window to implement the Code running function.
  17. Newwin.doc ument. Close ();
  18. }
  19. }
  20. Function copycode (ID)
  21. {
  22. VaR text2copy = Document. getelementbyid (ID). value;
  23. If (window. clipboardData)
  24. {
  25. Window. clipboardData. setdata ("text", text2copy );
  26. }
  27. Else
  28. {
  29. VaR flashcopier = 'flashcopier ';
  30. If (! Document. getelementbyid (flashcopier ))
  31. {
  32. VaR divholder = Document. createelement ('div ');
  33. Divholder. ID = flashcopier;
  34. Document. Body. appendchild (divholder );
  35. }
  36. Document. getelementbyid (flashcopier). innerhtml = '';
  37. VaR divinfo = '<embed src = "_clipboard.swf" flashvars = "Clipboard =' + escape (text2copy) + '"width =" 0 "Height =" 0 "type =" application/X-Shockwave-flash "> </embed>'; // The key here
  38. Document. getelementbyid (flashcopier). innerhtml = divinfo;
  39. }
  40. Return true;
  41. }
  42. Function savecode (ID ){
  43. VaR tcode = Document. getelementbyid (ID). value;
  44. VaR winname = Window. Open ('', '_ blank', 'top = 10000 ');
  45. Winname.doc ument. Open ('text/html ', 'replace ');
  46. Winname.doc ument. writeln (tcode );
  47. Winname.document.execcommand('saveas', '', 'code.html ');
  48. Winname. Close ();
  49. }
  50. Function createmap (){
  51. VaR MAP2 = new ltmaps ("MAP2 ");
  52. Map2.centerandzoom (New ltpoint (41540969,3994940), 6 );
  53. VaR points = new array ();
  54. Points. Push (New ltpoint (11629376,399 5776 ));
  55. Points. Push (New ltpoint (11642688,398 8608 ));
  56. Points. Push (New ltpoint (11641152,399 2640 ));
  57. VaR polyline = new ltpolyline (points );
  58. Map2.addoverlay (polyline );
  59. }
  60. </SCRIPT>
  61. <Textarea name = "textarea" Cols = "60" rows = "10" id = "rn01">
  62. <HTML xmlns: V = "urn: Schemas-Microsoft-com: VML">
  63. <Head>
  64. <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
  65. <Meta name = "keywords" content = ""/>
  66. <Title> Map </title>
  67. <Style type = "text/CSS"> V/: * {behavior: URL (# default # VML);} </style>
  68. <SCRIPT type = "text/JavaScript" src = "http://api.51ditu.com/js/maps.js"> </SCRIPT>
  69. <SCRIPT type = "text/JavaScript">
  70. Function createmap (){
  71. VaR MAP2 = new ltmaps ("MAP2 ");
  72. Map2.centerandzoom (New ltpoint (41540969,3994940), 6 );
  73. VaR points = new array ();
  74. Points. Push (New ltpoint (11629376,399 5776 ));
  75. Points. Push (New ltpoint (11642688,398 8608 ));
  76. Points. Push (New ltpoint (11641152,399 2640 ));
  77. VaR polyline = new ltpolyline (points );
  78. Map2.addoverlay (polyline );
  79. }
  80. </SCRIPT>
  81. </Head>
  82. <Body onload = "createmap ()">
  83. <Div id = "MAP2" style = "width: 400px; Height: 300px;"> </div>
  84. </Body>
  85. </Html>
  86. </Textarea>
  87. <Br> <input onclick = "runcode ('rn01')" type = "button" value = "run code" style = "cursor: Hand">
  88. <Input type = button value = "copy" onclick = "copycode ('rn01')">
  89. <Input type = button value = "save" onclick = "savecode ('rn01')">
  90. <Br/>
  91. </Body>
  92. </Html>

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.