javascript - Tinymce on keypress I am try to display the preview of the content - Stack Overflow

I am trying below code$('textarea.tinymce').keypress(function(){dealDescription = $('tex

I am trying below code

 $('textarea.tinymce').keypress(function(){
      dealDescription = $('textarea.tinymce').tinymce().execCommand('mcePreview');
      $("#deal_preview div").text(dealDescription);
 });

But I am not using jquery tinymce editor suppose I use jquery tinymce and other jquery UI ponent not working properly so I am directly using the tinymce ponent.

Now I need to show content preview in preview box for each key press.

I am trying below code

 $('textarea.tinymce').keypress(function(){
      dealDescription = $('textarea.tinymce').tinymce().execCommand('mcePreview');
      $("#deal_preview div").text(dealDescription);
 });

But I am not using jquery tinymce editor suppose I use jquery tinymce and other jquery UI ponent not working properly so I am directly using the tinymce ponent.

Now I need to show content preview in preview box for each key press.

Share Improve this question asked Apr 23, 2011 at 18:13 ElankeeranElankeeran 6,1849 gold badges42 silver badges57 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Im using this in tinymce 4.x

tinymce.init({
    selector: "#tinymce-textarea",
    setup : function(ed) {
        ed.on("change", function(e){
            $('#tinymce-livepreview').html(tinymce.activeEditor.getContent());
        });
        ed.on("keyup", function(){
            $('#tinymce-livepreview').html(tinymce.activeEditor.getContent());
        });
   }
});

Explanation:

on("change") is for detect changes on mouse event if u click toolbar icon or selection from the menu. It also able to detect the keyboard event but only after lost focus (not real time).

on("keyup") is for detect changes on real time keyboard event

Could be done after initialisasing as well by getting the active editor:

tinyMCE.activeEditor.on('keyup', function () {
    // your nicely formatted code here
});

There's also an editors array you can iterate over if you need it.

I try with below code is working fine

tinyMCE.init({

    mode : "exact",
    elements : "text",

    setup : function (theEditor) {
        theEditor.onKeyPress.add(
            function (theEditor) {
                previewContent(theEditor);
            }
        );
    },
});

function previewContent(editorObject){
     var content = editorObject.getContent();
     document.getElementById("previewContent").innerHTML = content;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745240063a4618128.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信