[Project_owners] Cancelling Web page selection

Alex Eng ateng at users.sourceforge.net
Sat Dec 10 21:50:46 EST 2005

Neil wrote:
> Alex Eng wrote:
>> Neil wrote:
>>> Alex Eng wrote:
>>>> What I want to do is extract all text inside a rich edit box (i.e., 
>>>> an HTML document inside an <iframe> with designMode = "on"), while 
>>>> still keeping line breaks.
>>>> There are other approaches I explored, but they didn't work out:
>>>> - Using the DOM Range methods.  Calling rangeObject.toString() 
>>>> retrieves all the text, but line breaks are lost and the extracted 
>>>> plain text is a garbled mess.
>>> Well, this javascript bookmarklet worked for me on a random web page:
>>> javascript: var range = document.createRange(); 
>>> range.selectNode(document.body); alert(range.toString());
>> That gives you back text with line breaks from the original HTML 
>> source, not the line breaks the user sees when the HTML is rendered in 
>> the browser.  Try doing a Select All on a Web page, then execute the 
>> following:
>>   javascript:alert(window.getSelection());
>> Compare that with the output from your bookmarklet code.  The result 
>> from window.getSelection() is what I want.
> I'm sorry, I see now that my code is the same as 
> document.body.textContent whereas what you want is the same effect as 
> saving the page as text. In that case, you need to get hold of the 
> nsIEditor object for the rich editor, you can then call its 
> outputToString method. This is easier if you can use an <editor> rather 
> than an <iframe>, but I think it should be possible for an <iframe> too.

The <iframe> element, which contains the HTML document with 
designMode="on", is contained in an HTML document which I am accessing 
from JavaScript code in my Firefox extension.  It's not an <iframe> in 
XUL.  I should have been more clearer in my original problem 
description, rephrased below:

"What I want to do is extract all text inside an HTML rich edit box 
(i.e., an HTML document with designMode = 'on', enclosed inside an 
<iframe> element of an outer HTML document), as if I were saving the 
<iframe> content as text."

But you've got the idea of what I want in terms of line breaks.

More information about the Project_owners mailing list