function addHref(des){
var selectedText="";
if(window.getSelection&&des != undefined){//Compatible with non-IE browsers, because non-IE browsers require elements for a given operation Only ID can get the selected content in the input element, so you need to enter the ID
var textField=document.getElementById(des);
var selectionStart=textField.selectionStart;
var selectionEnd=textField.selectionEnd ;
if(selectionStart != undefined && selectionEnd != undefined){
selectedText=textField.value.substring(selectionStart,selectionEnd);
}
if(selectedText==""){
alert("Please select the text to add a link to!");
return;
}
var hyperlinks=prompt("Hyperlink address:","");
if(hyperlinks !=null){
var replaceString="
" selectedText "";
tmpStr=textField.value;
textField.value=tmpStr.substring(0,selectionStart) replaceString tmpStr. substring(selectionEnd,tmpStr.length);
}
}
else if((document.selection)&&(document.selection.type == "Text")){//ID is not required in IE
var range=document.selection.createRange();
var formerElement=range.parentElement();
if(formerElement.tagName!="TEXTAREA"){
alert("Please specify Position the text where you want to add a hyperlink! ");
return;
}
selectedText=range.text;
var hyperlinks=prompt("Hyperlink address: ","");
if(hyperlinks!=null) {
range.text="
" selectedText "< /font>";
}
}
else{
alert("Please select the text to add a link to!");
return;
}
}