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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |