Insert html at caret in a contenteditable div

后端 未结 4 1499
予麋鹿
予麋鹿 2020-11-22 06:57

I have a div with contenteditable set and I am capturing keypress using jquery to call preventDefault() when the enter key is pressed. Similar to this question which insert

4条回答
  •  滥情空心
    2020-11-22 07:40

    by reading quickly and hoping not to be off topic, here is a track for those who, like me, need to insert code at the cursor level of a div:

    document.getElementById('editeur').contentWindow.document.execCommand('insertHTML', false, '
    ');

    'editeur' is iframe :

    
    

    contenu_editeur_wysiwyg.php :

    
    
        
    
    
    

    don't forget :

    document.getElementById('editeur').contentDocument.designMode = "on";
    

提交回复
热议问题