f



iframe pasteHTML

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?
0
Rauan
2/15/2008 10:01:34 AM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

3 Replies
52179 Views

Similar Articles

[PageSpeed] 3

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.
0
Rauan
2/18/2008 10:48:44 AM
On Feb 15, 3:01 pm, Rauan Maemirov <rauan1...@gmail.com> wrote:
> 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 :)
0
Aditya
2/18/2008 10:49:03 AM
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.
0
Rauan
2/18/2008 11:11:04 AM
Reply: