Mam funkcję do pobierania kodu html:
function getSelectionHtml () { var html = ""; if (typeof window.getSelection != "undefined") { var sel = window.getSelection(); if (sel.rangeCount) { var container = document.createElement("div"); for (var i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); } html = container.innerHTML; } } else if (typeof document.selection != "undefined") { if (document.selection.type == "Text") { html = document.selection.createRange().htmlText; } } return html; }
Z tym, że działa ona nie tak jak potrzebuję, mianowicie w przypadku gdy mamy kod html:
i na stronie zaznacze interesujący mnie tekst, chce otrzymać wynik:
<p>teks
A zwraca niestety całość, ze wszystkimi zamkniętymi i otwartymi tagami.
Jakieś naprowadzenie, pomysł jak to poprawić?