TinyMCE installation script - InitTinyMCE.js
tinymce.init({ selector: '#forTinyMCE', width: 700, height: 100, resize: false, plugins: 'link emoticons table code image', menubar: "edit insert view format tools", toolbar1: 'fontselect fontsizeselect | bullist numlist | outdent indent blockquote ', toolbar2: 'code | undo redo | removeformat subscript superscript | alignleft aligncenter alignright alignjustify', toolbar3: 'table | bold italic underline strikethrough | link unlink | emoticons | image responsivefilemanager', relative_urls: false, setup: function (editor) { //ΠΏΡΠΈ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ΅ tinyMCE editor.on('NodeChange', function (e) { // ΠΏΡΠΈ Π²ΡΡΠ°Π²ΠΊΠ΅ var view = document.getElementById("view"); // Π½Π°ΡΠ»ΠΈ ΠΏΠΎΠ»Π΅ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ view.innerHTML = editor.getContent(); // ΡΠΈΠ½Ρ
ΡΠΎΠ½ΠΈΠ·ΠΈΡΠΎΠ²Π°Π»ΠΈΡΡ }); editor.on('keypress', function (e) { // ΠΏΡΠΈ Π½Π°ΠΆΠ°ΡΠΈΠΈ ΠΊΠ»Π°Π²ΠΈΡΠΈ var view = document.getElementById("view"); view.innerHTML = editor.getContent(); }); } });
HTML page
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="//tinymce.cachefly.net/4.2/tinymce.min.js" defer></script> <script type="text/javascript" src="jslib/InitTinyMCE.js" defer></script> <title>ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ tinymce</title> </head> <body> <div style="margin: 0 25%; position: relative"> <form action="post/postPool.php" name="textForm" method="post"> <textarea name="text" id="forTinyMCE" style="width: 200px; height: 100px;">Easy! You should check out MoxieManager!</textarea> <!--<input type="submit" value="Upload">--> </form> <div id="view" style="width: 700px; height: 200px; background: lightgoldenrodyellow; overflow: auto"> </div> </div> </body> </html>
Under the editor, the field with which the editor is synchronized. Idea: just handle the key press events and field changes (if the text inserts the key handler does not work) and overwrite the contents of the editor in a special field.
PS: You can use the change event, but it is not generated every time you press a key and not every time you change the text in the editor.
Update: The document.getElementById('#textarea') code is incorrect. Write document.getElementById('textarea') without # . And it is better not to use such id. Write at least mytextarea .
<textarea>field - Vladimir Htextareais a text editing field, and on stackoverflow we edit the message in puretextareawhich displays some similarity to the source code of the message, and how it will look is already below. TinyMCE - WYSYWIG editor - its meaning is that it immediately shows what happens, like MS Word, and the source code is hidden, the same will be displayed from the bottom as inside (on SO this is not at all). You need it? - RussCoder