Discussion:
howto get HTML code from selection?
h***@gmail.com
2007-01-06 16:19:50 UTC
Permalink
I have a selection object (and I can do range from it). How to get HTML
code of this selection or range?
Martijn
2007-01-06 16:45:57 UTC
Permalink
You should be able to just do .toString() on it.
See also: http://developer.mozilla.org/en/docs/DOM:Selection

Regards,
Martijn
Post by h***@gmail.com
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
https://lists.mozilla.org/listinfo/dev-tech-dom
--
Martijn Wargers
Help Mozilla!
http://weblogs.mozillazine.org/qa/
http://www.mozilla.org/contribute/
h***@gmail.com
2007-01-06 16:58:37 UTC
Permalink
But that function clean HTML tags.
"""Martijn писал(а):
"""
Post by Martijn
You should be able to just do .toString() on it.
See also: http://developer.mozilla.org/en/docs/DOM:Selection
Regards,
Martijn
Martin Honnen
2007-01-06 17:00:18 UTC
Permalink
Post by h***@gmail.com
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/
h***@gmail.com
2007-01-06 17:13:20 UTC
Permalink
Big thanks!
"""Martin Honnen wrote:
"""
Post by Martin Honnen
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);
}
schnee
2009-10-28 16:49:56 UTC
Permalink
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?
Post by h***@gmail.com
Big thanks!
"""
Post by Martin Honnen
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);
}
schnee
2009-10-28 17:20:11 UTC
Permalink
Forget this message and excuse me.
I do get the HTML. My mistake...
Post by schnee
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?
Post by h***@gmail.com
Big thanks!
"""
Post by Martin Honnen
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);
}
Loading...