Use of the IFRAME editor JS under IE
var IFR = document.getElementById (' IFR ');
var srange=doc.selection.createrange ();
Srange.execcommand (' Insertimage ', false,image_src);
To insert the picture, the picture is always inserted in front of the editor, so look for the problem, accidentally in a blog to know the reason (the specific address negligence did not write down)
The reason is that under IE, when the cursor disappears in the box, it will go back to the starting position when inserting it (because the cursor will disappear if you want to display the prompt picture being loaded)
So the diagram is inserted in front, here is the method provided in the data:
/**
* Record IE's edit cursor
*/
document.getElementById (' IFR '). ContentWindow.document.onbeforedeactivate =function () {
var Contentwindow = document.getElementById (' IFR '). Contentwindow;
var range = ContentWindow.document.selection.createRange ();
Ieselectionbookmark = Range.getbookmark ();
};
/**
* Reset IE's edit cursor
*/
if (Ieselectionbookmark) {
var Contentwindow = document.getElementById (' IFR '). Contentwindow;
var range = Doc.body.createTextRange ();
Range.movetobookmark (Ieselectionbookmark);
Range.Select ();
Ieselectionbookmark = null;
};
When resetting, be sure to insert the content method of the IFrame that is compatible with IE FF before inserting the image:
var IFR = document.getElementById (' IFR ');
$ (' #sms_loading '). Hide ();
if (Browser_type = = ' ie ') {
Ifr.contentWindow.focus ();
var doc = Ifr.contentdocument | | Ifr.contentWindow.document;
var srange=doc.selection.createrange ();
Srange.execcommand (' Insertimage ', false,response.showpic);
}else{
Ifr.focus ();
var rng = Ifr.contentWindow.getSelection (). Getrangeat (0);
var FRG = rng.createcontextualfragment (response.showpic);
Ifr.contentWindow.document.execCommand (' Insertimage ', false,response.showpic);
}
Among them about the use of ExecCommand method, online There are many examples at random Baidu can.
2014-11-11
From the Baidu Space migration
The cursor positioning problem in IFRAME ie