@zjuupauthorJul 26.2006 — #[CODE]// DES: Gets the active selected text // RET: The selected text. EMPTY STRING when there is no selection function getSelectedText(){ if (document.selection != undefined){ if (document.selection.type == "Text"){ return document.selection.createRange().text; } // if } // if return ""; } // getSelectedText[/CODE]
@zjuupauthorJul 26.2006 — #[CODE]// DES: Function retrieves the startposition of the selected text within the current parents control // PAR: parParentControl = A reference to the control containing the selection. // RET: The start position of the selected text. // -1 if the selection did not exist // -2 The parentcontrol is undefined function getSelectedTextPosition(parParentControl){
var intResultPosition = -1; var strSelection = getSelectedText();
if (parParentControl == undefined){ intResultPosition = -2; // no parent control
} else if (strSelection.length > 0){
var objTextRange = document.selection.createRange();
// Overwrite the text, identifying the position of the selection objTextRange.text = "~!@" + strSelection + "@!~";
// Get the text 'selection' var strParentElementText = parParentControl.value;
// Restore the original text objTextRange = document.selection.createRange(); objTextRange.text = strSelection; intResultPosition = strParentElementText.indexOf("~!@" + strSelection + "@!~");
} // if return intResultPosition;
} // getSelectedTextPosition
// DES: Gets the active selected text // RET: The selected text. EMPTY STRING when there is no selection function getSelectedText(){ if (document.selection != undefined){ if (document.selection.type == "Text"){ return document.selection.createRange().text; } // if } // if return ""; } // getSelectedText[/CODE]