Javascript Internet Explorer中范围/选择中的原始标记
我通过此功能提取用户选择的内容:Javascript Internet Explorer中范围/选择中的原始标记,javascript,html,internet-explorer,selection,markup,Javascript,Html,Internet Explorer,Selection,Markup,我通过此功能提取用户选择的内容: function getSelectionHTML() { var userSelection; if (window.getSelection) { // W3C Ranges userSelection = document.getElementById('axPage').contentWindow.getSelection(); // Get the range: if (userSelection.getRan
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 '';
}
};
提取工作正常,但我似乎没有找到在Internet Explorer中获取所选文本的原始标记的方法。有没有办法像Firefox那样获得DocumentFragment?我知道这两个系统的不同处理方式和方法,但也许有人已经在javascript/ECMA中找到了一种有效的方法来摆脱HREFs中令人讨厌的…jqueryxxxxxxxxxxx=“12”加载项以及令人痛苦的大写标记和属性名称
再次强调:必须选择准确的标记
非常感谢您的帮助。您在IE中的唯一选择是编写代码在选择边界点之间漫游DOM,或者在执行操作时使用选择文本范围中的
htmlText
。第一种选择将相当复杂。我真的不明白第二种方法的问题是什么:你能更精确一点,或者举个例子说明你从htmlText得到的HTML有什么问题吗?谢谢你的帮助,我终于找到了答案。如果您需要在Internet Explorer中使用小写标记获取所选文本,请尝试此功能,如果您使用jquery并具有令人讨厌的小字符。jqueryxxxxxxx=“12”13,14在每次href=“”-closing”之后,您的解决方案是将标记复制到div并读取其内部HTML
希望有帮助