简体   繁体   中英

javascript onkeypress error live Preview text CKEditor without text Area

I have CKEditor WYSIWYG I want to live print the content in another div But all attempts failed Because the box is div not textarea please help . I used this code

var wpcomment = document.getElementById('CKEditordiv');

wpcomment.onkeyup = wpcomment.onkeypress = function(){
    document.getElementById('printdiv').innerHTML = this.value;
}

Also you add id to body CKEditor

<body id="CKEditordiv" contenteditable="true" class="cke_editable cke_editable_themed cke_contents_ltr" spellcheck="false"><p><br></p></body>

and print id div

<div id="image-holdere"></div>

i use this code

http://jsfiddle.net/m7mdq8vs/

Try using code like this one (it's a good starting point):

var editor = CKEDITOR.replace( 'editor1', {});
editor.on( 'instanceReady', function( evt ) {
    editor.on( 'saveSnapshot', function( e ) {                  
        document.getElementById( 'insert-here' ).innerHTML  = editor.getSnapshot();                 
    });
});         

editor.on( 'key', function( evt ) {
    document.getElementById( 'insert-here' ).innerHTML  =  editor.document.getBody().getHtml();
}); 

You can put is directly on HTML page. If you need just typing you can only use the key event if however you need to show what plugins insert, you need to use saveSnapshot event as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM