I try to get the starting element and the ending selection element and selection bias in each, I do it in firefox like this:
var delselection = window.getSelection(); var startOffset = delselection.anchorOffset; var endOffset = delselection.focusOffset; var startNode = delselection.anchorNode.parentNode; var endNode = delselection.focusNode.parentNode;
However, I have no idea how to do this in IE6, who can point me in the right direction?
document.selection.
TextRange, IE, Firefox/WebKit/W3, . , , - range.parentElement(), range.inRange() range.compareEndPoints(). range.execCommand().
IE Range Mozilla/Webkit/W3, , , , .
ControlRange TextRange IE BOM.
AnchorOffset, focusOffset window.getSelection() IE6/7. .
If you know the object in which the selection is located (for example, this is an input field that the user enters in what you want to change during typing), this code does the trick:
var selObj = null; var selSave = null; var selSaveEnd = null; function SaveSelection(obj) { if (obj.selectionStart) { selObj = obj; selSave = obj.selectionStart; selSaveEnd = obj.selectionEnd; } else { // Internet Explorer case selSave = document.selection.createRange(); } } function RestoreSelection() { if (selObj) { selObj.focus(); selObj.selectionStart = selSave; selObj.selectionEnd = selSaveEnd; } else { // Internet Explorer case selSave.select(); } }