iframe pasteHTML

R

Rauan Maemirov

Hi, I'm coding smth like wysiwyg-editor and stumbled upon some
obstacles.

var iDoc = $(this.wysiwyg.contentWindow.document);
var sel = (iDoc.selection) ? iDoc.selection :
this.wysiwyg.contentWindow.getSelection();

if (Prototype.Browser.IE) {
var rng = sel.createRange();
rng.pasteHTML(html);
} else {
// Firefox and opera code
}

So, in this code I'm inserting html to the iframe (with
contentEditable/designMode = true/on ).

Where this.wysiwyg = $('iframe'). //dynamically created iframe

In IE it doesn't insert html to iframe, but to the top of my main
document, right after the <body> tag.

The reason is I'm clicking on link and div appears (Google Docs link
inserting style). So iframe looses
focus. But in firefox it doesn't. Maybe there are any ways how to
remember previous focus position?
 
R

Rauan Maemirov

The only way I find, is to save range. And then insert html to it.

Is there way to save range and then use it? I tried but it doesn't
work.
 
A

Aditya

Hi, I'm coding smth like wysiwyg-editor and stumbled upon some
obstacles.

var iDoc = $(this.wysiwyg.contentWindow.document);
var sel = (iDoc.selection) ? iDoc.selection :
this.wysiwyg.contentWindow.getSelection();

if (Prototype.Browser.IE) {
var rng = sel.createRange();
rng.pasteHTML(html);} else {

// Firefox and opera code

}

So, in this code I'm inserting html to the iframe (with
contentEditable/designMode = true/on ).

Where this.wysiwyg = $('iframe'). //dynamically created iframe

In IE it doesn't insert html to iframe, but to the top of my main
document, right after the <body> tag.

The reason is I'm clicking on link and div appears (Google Docs link
inserting style). So iframe looses
focus. But in firefox it doesn't. Maybe there are any ways how to
remember previous focus position?


try setting focus to iframe just before rng.pasteHTML(html)
by calling .focus() on the iframe node..
i hope it will work.....tell me if it does :)
 
R

Rauan Maemirov

Thanks, Aditya!!!

You don't event know, how long I've been seeking for solution. Your
advice helped me. My way is:

1). When I'm clicking on insertLink-button(image) I'm doing:

this.wysiwyg.contentWindow.focus();
var iDoc = this.wysiwyg.contentWindow.document;
var sel = (iDoc.selection) ? iDoc.selection :
this.wysiwyg.contentWindow.getSelection();
this.rng = (sel.rangeCount > 1) ? sel.getRangeAt(rangeCount - 1) :
sel.createRange();

2). When clicking "Insert" on the form I'm using
this.rng.pasteHTML(html).

I.e. I'm saving the range and then using it, but not getting selection
again, 'cause it would return main document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top