ajax.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
  4. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  5. -->
  6. <html lang="en">
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Ajax &mdash; CKEditor Sample</title>
  10. <script src="../../ckeditor.js"></script>
  11. <link rel="stylesheet" href="sample.css">
  12. <meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
  13. <script>
  14. var editor, html = '';
  15. function createEditor() {
  16. if ( editor )
  17. return;
  18. // Create a new editor inside the <div id="editor">, setting its value to html
  19. var config = {};
  20. editor = CKEDITOR.appendTo( 'editor', config, html );
  21. }
  22. function removeEditor() {
  23. if ( !editor )
  24. return;
  25. // Retrieve the editor contents. In an Ajax application, this data would be
  26. // sent to the server or used in any other way.
  27. document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData();
  28. document.getElementById( 'contents' ).style.display = '';
  29. // Destroy the editor.
  30. editor.destroy();
  31. editor = null;
  32. }
  33. </script>
  34. </head>
  35. <body>
  36. <h1 class="samples">
  37. <a href="index.html">CKEditor Samples</a> &raquo; Create and Destroy Editor Instances for Ajax Applications
  38. </h1>
  39. <div class="warning deprecated">
  40. This sample is not maintained anymore. Check out its <a href="https://ckeditor.com/docs/ckeditor4/latest/examples/saveajax.html">brand new version in CKEditor Examples</a>.
  41. </div>
  42. <div class="description">
  43. <p>
  44. This sample shows how to create and destroy CKEditor instances on the fly. After the removal of CKEditor the content created inside the editing
  45. area will be displayed in a <code>&lt;div&gt;</code> element.
  46. </p>
  47. <p>
  48. For details of how to create this setup check the source code of this sample page
  49. for JavaScript code responsible for the creation and destruction of a CKEditor instance.
  50. </p>
  51. </div>
  52. <p>Click the buttons to create and remove a CKEditor instance.</p>
  53. <p>
  54. <input onclick="createEditor();" type="button" value="Create Editor">
  55. <input onclick="removeEditor();" type="button" value="Remove Editor">
  56. </p>
  57. <!-- This div will hold the editor. -->
  58. <div id="editor">
  59. </div>
  60. <div id="contents" style="display: none">
  61. <p>
  62. Edited Contents:
  63. </p>
  64. <!-- This div will be used to display the editor contents. -->
  65. <div id="editorcontents">
  66. </div>
  67. </div>
  68. <div id="footer">
  69. <hr>
  70. <p>
  71. CKEditor - The text editor for the Internet - <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
  72. </p>
  73. <p id="copy">
  74. Copyright &copy; 2003-2023, <a class="samples" href="https://cksource.com/">CKSource</a> Holding sp. z o.o. All rights reserved.
  75. </p>
  76. </div>
  77. </body>
  78. </html>