indexing - Javascript + How to get the index w.r.t the parent Node of selection + Browsers Other than IE -


Hi I want to start the selection and the end index regarding the parent node of the selected text. I am able to do this in IE. Although in other browsers like Firefox, Opera, Safari and Chrome, I'm able to get the selection and indicator of selected text. But for my requirement the index w.r.t is to get the parent node and not the selected node. I need a solution that supports all browsers - Firefox, Opera, Safari and Chrome

  if (window.getSelection) {warning ("other browser"); Sel = window.getSelection (); If (sel! = '') {//alert(sel.anchorNode.parentNode.nodeName); //alert(sel.anchorOffset); //alert(sel.focusNode.parentNode.nodeName); //alert(sel.focusOffset); }} And if (document.selection) {txt = document.selection.createRange () Text; Var rang_all = document.body.createTextRange (); If (txt! = '') {// Know the starting position range = document.section.createren (); Range.collapse (true); Var startParentElement = range.parentElement (); Range_all.moveToElementText (startParentElement); (Var sel_start = 0; range_all.compareEndPoints (for 'StartToStart', category) & lt; 0; sel_start ++) range_all.moveStart ('character', 1); Category = Document.Subtion.CreatorZone (); Range.collapse (wrong); Range_all = document.body.createTextRange (); Var EndpileAlement = Series Parent element (); Range_all.moveToElementText (endParentElement); (Var sel_end = 0; range_all.compareEndPoints (for 'StartToEnd', category) & lt; 0; sel_end ++) range_all.moveStart ('character', 1); Warning ("sel_start:" + sel_start); Warning ("sel_end:" + sel_end); }}  

The QuirksMode site can help you:

You just need to know how to use range objects in browsers other than IE.


Comments