UPDATE:
You can see the code at http://jsfiddle.net/sV3us/1/
I got this function. It works with non IE browsers, but IE9 is not working. I'm calling this function with execCommandOnElement(testDiv, "insertHTML", "some content")
function execCommandOnElement(el, commandName, value) {
if (typeof value == "undefined") {
value = null;
}
if (typeof window.getSelection != "undefined") {
// Non-IE case
// Temporarily enable designMode so that
// document.execCommand() will work
document.designMode = "on";
//place caret
selection.collapse (anchorNode, anchorOffset);
selection.extend( focusNode, focusOffset);
// Execute the command
document.execCommand(commandName, false, value);
// Disable designMode
document.designMode = "off";
}
else if (typeof document.body.createTextRange != "undefined") {
close_modal ();
// IE case
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
document.execCommand(commandName, false, value);
}
}
I dont need to select something in my content editable div (for example to bold a text), I just need that IE pastes the HTML where the caret is placed. Because I need to use dialog box to get some content to paste, I use this function to know where to place it.
//launch
$(".launch_modal").click(function() {
open_modal ( $(this).attr( 'data-modal' ) );
selection = window.getSelection() ;
anchorNode = selection.anchorNode;
anchorOffset = selection.anchorOffset;
focusNode = selection.focusNode;
focusOffset = selection.focusOffset;
});
I really appreciate your help. I have been in this all day.