See UBB Code [Code] The "Copy to clipboard" function is available in windows. I think it is very useful.
After a file is uploaded, add a copy button to the URL that appears at the "address (PATH)" location.
I studied the original code ..
Define functions
ProgramCode view plaincopy to clipboardprint?
-
- FunctionCopytext (OBJ ){
-
- Ie = (document. All )?True:False
-
- If(IE ){
- VaRRNG = Document. Body. createTextRange ();// List all text objects
-
- RNG. movetoelementtext (OBJ );// Move the text range so that the start and end positions of the range can fully contain the text of the given element
-
- RNG. scrollintoview ();// Scrollintoview: Scroll the object to the visible range and arrange it
-
- Top or bottom of the window
-
- RNG. Select ();// Select
-
- Rng.exe ccommand ("Copy");// Copy
- RNG. Collapse (False);// Not quite clear ..
-
- }
-
- }
function copytext (OBJ) {<br/> Ie = (document. all )? True: false <br/> If (IE) {<br/> var RNG = document. body. createTextRange (); // list all text object content <br/> RNG. movetoelementtext (OBJ); // move the text range so that the start and end positions of the range can fully contain the text of the given element <br/> RNG. scrollintoview (); // scrollintoview the object to the visible range and arrange it to the top or bottom of the <br/> window <br/> RNG. select (); // select <br/> rng.exe ccommand ("copy"); // copy <br/> RNG. collapse (false); // not clear .. <br/>}< br/>
then use
program code
[Copy code to clipboard]
code...
It mainly selects the Text object to be copied, and then uses execommand ("copy") to copy.
After that, I took a photo of the class and found that the content in <input type = text> could not be copied... only the outer box could be selected ..
I found some information on the internet... I finally got the answer ..
========================================================== =
Javascript tip (1) operate the clipboard
Javascript allows you to easily operate the client clipboard content, but it is only applicable to ie5 and later browsers.
Javascript can use the window. clipboardData object to process the clipboard content.
Method for saving to clipboard setdata (param1, param2)
Param1: data type, such as text or URL.
Param2: data content
Getdata (param1)
Data clearing method cleardata (param1)
The following is an example
Program code view plaincopy to clipboardprint?
-
-
- <Html>
-
- <Head>
- <Title>Test Operation clipboard</Title>
-
- </Head>
-
- <Script>
-
- Function copytoclipboard ()
-
- {
-
- VaRD=Document. All ("Source"). value;
- Window. clipboardData. setdata ('text', d );
-
- }
-
-
- </Script>
-
- <Body >
-
- <Button Onclick="Copytoclipboard ();">Copy</Button>
-
- <Input Type="Text" Size=20 ID="Source" Value="Test Data">
- <BR>
-
- <Button Onclick="Alert (window. clipboardData. getdata ('text '));">Display</Button>
-
- <Button Onclick="Window. clipboardData. cleardata ('text ');">Clear</Button>
-
-
- </Body>
-
- </Html>
-
<HTML> <br/> <pead> <br/> <title> test operation clipboard </ title> <br/> </pead> <br/> <SCRIPT> <br/> function copytoclipboard () <br/>{< br/> var d = document. all ("Source "). value; <br/> window. clipboardData. setdata ('text', d ); <br/>}< br/> </SCRIPT> <br/> <body> <br/> <button onclick = "copytoclipboard (); "> copy </button> <br/> <input type =" text "size = 20 id =" Source "value =" Test Data "> <br/> <br> <br/> <button onclick = "alert (window. clipboardData. getdata ('text'); "> display </button> <br/> <button onclick =" window. clipboardData. cleardata ('text '); "> clear </button> <br/> </body> <br/> </ptml> <br/>
The following is an example implementation page. selected characters, and drag it to the hosts area
note the window. event. the datatransfer object can also process the clipboard content, but it can only be used in the drag-and-drop operation
Program code view plaincopy to clipboardprint?
-
- <Html>
-
- <Head>
-
- <Title>Test Operation clipboard 2</Title>
-
- </Head>
-
- <Script>
-
- Function transferdrop (){
-
- WindowWindow. event. srcelement. innertext= Window. event. datatransfer. getdata ("text ");
-
- Window. event. returnvalue=False;
-
- }
-
- Function transferdrag (){
-
- Window. event. datatransfer. dropeffect='Move';
- Window. event. returnvalue=False;
-
- }
-
-
- </Script>
-
- <Body
-
- <P ID="Mysource" Ondragstart="Window. event. datatransfer. effectallowed=
-
- 'Move';">Select us and drag us to the textarea below</P>
-
- <Textarea ID="Mytarget" Ondrop="Transferdrop ();"
-
- Ondragover="Window. event. returnvalue = false ;" Ondragenter="Transferdrag ();">
-
- </Textarea>
-
- </Body>
-
- </Html>
<Textarea class = "html" style = "display: none "name =" code "rows =" 15 "Cols =" 100 "> <HTML> <br/> <pead> <br/> <title> test operation clipboard 2 </title> <br/> </pead> <br/> <SCRIPT> <br/> function transferdrop () {<br/> window. event. srcelement. innertext = Window. event. datatransfer. getdata ("text"); <br/> window. event. returnvalue = false; <br/>}< br/> function transferdrag () {<br/> window. event. datatransfer. dropeffect = 'move '; <br/> window. event. returnvalue = false; <br/>}< br/> </SCRIPT> <br/> <body <br/> <p id = "mysource" ondragstart = "window. event. datatransfer. export tallowed = <br/> 'move '; "> select and drag us to the following textarea </P> <br/> <textarea id =" mytarget "ondrop =" transferdrop (); "<br/> ondragover =" window. event. returnvalue = false; "ondragenter =" transferdrag (); "> <br/> </textarea> <br/> </body> <br/> </ptml> <br/> </textarea>
====================================
Discovery and use
Window. clipboardData. setdata ("text", value)
Window. clipboardData. getdata ("text ")
Window. clipboardData. cleardata ("text ")
It's easy to control the content of the clipboard ..