< Script Language = " Javascript " >
VaR AGT = Navigator. useragent. tolowercase ();
VaR IE = (AGT. indexof ( " MSIE " ) ! = - 1 ) && (AGT. indexof ( " Opera " ) = - 1 ) && (AGT. indexof ( " Omniweb " ) = - 1 ));
Function A (){
VaR Myarea = Document. getelementbyid ( " S " );
VaR Selection;
If ( ! IE ){
If (Myarea. selectionstart ! = Undefined ){
Selection = Myarea. value. substr (myarea. selectionstart, myarea. selectionend - Myarea. selectionstart );
}
} Else {
If (Window. getselection ){
Selection = Window. getselection ();
} Else If (Document. getselection ){
Selection = Document. getselection ();
} Else If (Document. Selection ){
Selection = Document. selection. createRange (). text;
}
}
Alert (selection)
}
</ Script >
< Input type = " Text " Value = " Testtest " ID = " S " Name = " S "
Onmouseup = " Javascript: () " />
Recently, I am using js to create a small project for word search on a web page and obtain the text selected by IE.
Document. selection. createRange (). text;
Firefox
Is
Window. getselection ();