I am extracting content selected by the user via this function:
function getSelectionHTML() {
var userSelection;
if (window.getSelection)
{
// W3C Ranges
userSelection = document.getElementById('axPage').contentWindow.getSelection();
// Get the range:
if (userSelection.getRangeAt)
var range = userSelection.getRangeAt (0);
else
{
var range = document.createRange ();
range.setStart (userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd (userSelection.focusNode, userSelection.focusOffset);
}
var clonedSelection = range.cloneContents ();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
return div.innerHTML;
}
else if (document.selection)
{
userSelection = self.frames['axPage'].document.selection.createRange();
return userSelection.htmlText;
}
else
{
return '';
}
};
Extraction is working fine, but I do not seem to find a way to get the original markup of the selected text in Internet Explorer. Is there any way to get a DocumentFragment like in Firefox? I know about the different handling and approach of both systems, but maybe someone has found a working approach in javascript / ECMA to get rid of the nasty ...jQueryXXXXXXXXXXXXX="12" addons in HREFs and that painful uppercase tag- and attributenames.
Again: it is essential to get the exact markup selected.
Any help is appreciated, thank you.