I want to insert some html in a contenteditable div.
When editing the content, the user clicks on an icon, a dialog pops and he enters the url & anchor text in the dialog. This causes that the editable div loses its focus and the link is inserted at the beginning of the div, not when the caret was. I tried many things but I'm stuck.
"rte" id of my editable content div
"link_add" id of button in dialog
$('#link_add').click(function (e)
{
$('#rte').focus();
document.execCommand('insertHTML', false, 'html content test');
close_modal ();
e.preventDefault();
});
I also tried the solution from set execcommand just for a div, using:
function execCommandOnElement(el, commandName, value)
But this empties the div and just paste the new content.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…