1

I am trying to get IE to paste to the current caret position in a contenteditable div. IE will paste fine if you have some text selected but if you have nothing selected it pastes your text to the top of the page. Is there a way to have it paste to the caret position instead of the top of the page?

<div id='ce' contenteditable='true'>select me...</div>
document.getElementById("insert").onclick = function() {
    document.selection.createRange().pasteHTML("-PASTED HTML-");
};

fiddle (remember, IE only)

James Montagne
  • 77,516
  • 14
  • 110
  • 130
user1873073
  • 3,580
  • 5
  • 46
  • 81

1 Answers1

1

The answer turned out to be .focus on the text area. The actual scenario used the body element instead of a textarea and document.body.focus() worked for that situation.

Here is the fixed fiddle for this question: jsfiddle.net/Sx2Lt/4 (IE ONLY)

user1873073
  • 3,580
  • 5
  • 46
  • 81