You have to add a hyperlink to the selection in the input box at work
Copy Code code as follows:
function Addhref (DES) {
var selectedtext= "";
if (window.getselection&&des!= undefined) {//compatible non IE browser, because non IE browser requires the element ID of the given operation to get the selected content in the INPUT element, 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 (Select the text you want to add a link to!) ");
Return
}
var hyperlinks=prompt ("hyperlink address:", "");
if (hyperlinks!=null) {
var replacestring= "<a href=" "+hyperlinks+" ' target= ' _blank ' ><b><u><font color= ' #686600 ' > ' + SelectedText + "</font></u></b></a>";
Tmpstr=textfield.value;
Textfield.value=tmpstr.substring (0,selectionstart) +replacestring+tmpstr.substring (selectionEnd,tmpStr.length);
}
}
else if ((document.selection) && (Document.selection.type = = "Text") {//ie does not require an ID
var range=document.selection.createrange ();
var formerelement=range.parentelement ();
if (formerelement.tagname!= "TEXTAREA") {
Alert (Select the text you want to add a hyperlink to at the specified location!) ");
Return
}
Selectedtext=range.text;
var hyperlinks=prompt ("hyperlink address:", "");
if (hyperlinks!=null) {
range.text= "<a href=" "+hyperlinks+" ' target= ' _blank ' ><b><u><font color= ' #686600 ' > ' + SelectedText + "</font></u></b></a>";
}
}
else{
Alert (Select the text you want to add a link to!) ");
Return
}
}