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

howto get HTML code from selection?

1,083 views
Skip to first unread message

homers...@gmail.com

unread,
Jan 6, 2007, 11:19:50 AM1/6/07
to
I have a selection object (and I can do range from it). How to get HTML
code of this selection or range?

Martijn

unread,
Jan 6, 2007, 11:45:57 AM1/6/07
to homers...@gmail.com, dev-te...@lists.mozilla.org
You should be able to just do .toString() on it.
See also: http://developer.mozilla.org/en/docs/DOM:Selection

Regards,
Martijn

On 6 Jan 2007 08:19:50 -0800, homers...@gmail.com


<homers...@gmail.com> wrote:
> I have a selection object (and I can do range from it). How to get HTML
> code of this selection or range?
>

> _______________________________________________
> dev-tech-dom mailing list
> dev-te...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-dom
>


--
Martijn Wargers
Help Mozilla!
http://weblogs.mozillazine.org/qa/
http://www.mozilla.org/contribute/

homers...@gmail.com

unread,
Jan 6, 2007, 11:58:37 AM1/6/07
to
But that function clean HTML tags.
"""Martijn писал(а):

Martin Honnen

unread,
Jan 6, 2007, 12:00:18 PM1/6/07
to
homers...@gmail.com wrote:
> I have a selection object (and I can do range from it). How to get HTML
> code of this selection or range?

Kind of a hack but in a HTML document you can do e.g.

var selection = window.getSelection();
var range = selection.getRangeAt(0);
if (range) {
var div = document.createElement('div');
div.appendChild(range.cloneContents());
alert(div.innerHTML);
}


--

Martin Honnen
http://JavaScript.FAQTs.com/

homers...@gmail.com

unread,
Jan 6, 2007, 12:13:20 PM1/6/07
to
Big thanks!

schnee

unread,
Oct 28, 2009, 12:49:56 PM10/28/09
to
Hi,
I know this subject is almost 3 years old, but I'm looking for the same solution, tried the patch,
and it doesn't work for me: still getting text with no HTML (FF 3.5)
Have you found another solution?

schnee

unread,
Oct 28, 2009, 1:20:11 PM10/28/09
to
Forget this message and excuse me.
I do get the HTML. My mistake...
0 new messages