How Refocus When Insert Image In Contenteditable Divs In Ie?
There is a div: in IE(7,8,9), then I click a button to insert an image with using the document.execCommand('insertImage') method. The
Solution 1:
Updated with simpler code
Here's some nasty code to do this. In other browsers, it seems to work anyway, so the following can be used as it is.
Demo: http://jsfiddle.net/timdown/mr7Ac/6/
Code:
functioninsertImage() {
var sel = document.selection;
if (sel) {
var textRange = sel.createRange();
document.execCommand('insertImage', false, "someimage.png");
textRange.collapse(false);
textRange.select();
} else {
document.execCommand('insertImage', false, "someimage.png");
}
}
Solution 2:
Try something like this (IE only):
functioninsertImage(){
if(document.selection){
var sel=document.selection;
var range=sel.createRange();
var amount=(document.addEventListener)?2:1;
document.execCommand('insertImage', false, 'url');
range.move('character',amount);
range.select();
}
return;
}
Post a Comment for "How Refocus When Insert Image In Contenteditable Divs In Ie?"