The cursor positioning problem in IFRAME ie

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.