Obtain the selected value (for IE and Firefox) in the input. This example is very good.
| The code is as follows: |
Copy code |
Function Preview (obj) { Var TestWin = open (''); TestWin.doc ument. write (obj. value ); } Function copyCode (obj ){ Var rng = document. body. createTextRange (); Rng. moveToElementText (obj ); Rng. scrollIntoView (); Rng. select (); Rng.exe cCommand ("Copy "); Rng. collapse (false ); } Function saveCode (obj ){ Var winname = window. open ('', '_ blank', 'Top = 10000 '); Winname.doc ument. open ('text/html ', 'replace '); Winname.doc ument. writeln (obj. value ); Winname.document.execcommand('saveas', '', 'homepage..htm '); Winname. close (); } Function addBookmark (title, url ){ If (window. sidebar ){ Window. sidebar. addPanel (title, url ,""); } Else if (document. all ){ Window. external. AddFavorite (url, title ); } Else if (window. opera & window. print ){ Return true; } } <Script language = "javascript"> Var agt = navigator. userAgent. toLowerCase (); Var ie = (agt. indexOf ("msie ")! =-1) & (agt. indexOf ("opera") =-1) & (agt. indexOf ("omniweb") =-1 )); Function (){ 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: a ()"/>
|
Run the code, copy the code, save the code, and add it to favorites.