[Project_owners] Cancelling Web page selection

Alex Eng ateng at users.sourceforge.net
Sat Dec 10 09:01:28 EST 2005


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.


More information about the Project_owners mailing list