Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting HTML out of selection / range from a web page in Mozilla Firefox

0 views
Skip to first unread message

Manish Chakravarty

unread,
Dec 28, 2009, 9:56:30 PM12/28/09
to dev-ext...@lists.mozilla.org
Hello,

I currently using the following the get the selected text from a webpage
into a custom firefox extension:

getSelectedText: function(){
var textWindow = document.commandDispatcher.focusedWindow;
var text = textWindow.getSelection();
if (text == null) {text =' ';}
text = text.toString();
text = text.replace(/^\s*$/ , "");
text = text.replace(/\r/g, "\r");
text = text.replace(/\n/g, "\n");
text = text.replace(/^\s+|\s+$/g , " ");
text = text.replace(new RegExp(/\u2019/g), "'");
text = text.replace(new RegExp(/\u201A/g), ",");
text = text.replace(new RegExp(/\u201B/g), "'");
return {str:text};
}

This works just fine for plain text.

My problem is that i want all the elements of the webpage copied as well (
kind of like the webclips feature in safari )

**Use case -** If the user selects through a webpage with formatted text and
images, I want the underlying HTML to get copied as well, so that I can
accurately paste it into another XUL window - even send the contents as a
rich HTML email if I so wish.

Any pointers?

X-Posted by me at at
http://stackoverflow.com/questions/1972689/getting-html-out-of-selection-range-from-a-web-page-in-mozilla-firefox
--
Manish Chakravarty
Senior Consultant
ThoughtWorks Studios

Blog: http://manish-chaks.livejournal.com/
LinkedIn: http://www.linkedin.com/in/manishchakravarty
Twitter: http://twitter.com/ManishChaks
Facebook: http://www.facebook.com/manish.chakravarty

0 new messages