Js click to copy the text to the clipboard, copy the image to the clipboard, js clipboard

Source: Internet
Author: User

Js click to copy the text to the clipboard, copy the image to the clipboard, js clipboard

Copy text:

[Html]View plaincopy
  1. <Table width = "99%" border = "0" cellpadding = "0" cellspacing = "0" class = "firtable">
  2. <Tr>
  3. <Th width = "100%" style = "color: white;"> <s: text name = "ticket details"> </s: text> </th>
  4. </Tr>
  5. <Tr>
  6. <Td align = "center">
  7. <Textarea name = "inquiryContact1" id = "inquiryContact1" rows = "15" cols = "60" readonly = "readonly"> </textarea>
  8. <Div id = "inquiryInfoDIV" style = "display: none">
  9. <S: property value = "inquiryContact" escape = "false"/>
  10. </Div>
  11. <Script> dojo. byId ("inquiryContact1"). innerText = dojo. byId ("inquiryInfoDIV"). innerText;
  12. </Script>
  13. </Td> </tr>
  14. <Tr>
  15. <Td align = "center">
  16. <Input type = "button" id = "button" name = "button" value = "copy" onclick = "copyContact ()"/>
  17. </Td> </tr> </table>

 

[Javascript]View plaincopy
  1. <Script type = "text/javascript">
  2. Var I = 0;
  3. Function copyContact (){
  4. Var contat = document. getElementById ("inquiryContact1"). value;
  5. Window. clipboardData. setData ('text', contat );
  6. If (window. clipboardData. getData ('text') = ''){
  7. If (I = 1 ){
  8. Alert ("failed to copy. Please manually press Ctrl + C to copy! ");
  9. } Else {
  10. Alert ("copying failed. Please copy again! ");
  11. I = 1;
  12. }
  13. } Else {
  14. Alert ("the content has been copied to the clipboard! ");
  15. }
  16. }
  17. </Script>

 

Copy image:

[Html]View plaincopy
  1. <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <Html>
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  5. <Title> Insert title here </title>
  6. <Script language = "JScript">
  7. Var oPopup = window. createPopup ();
  8. Function ButtonClick (div)
  9. {
  10. // Var div = document. getElementById ('divid ');
  11. Div. contentEditable = 'true ';
  12. Var controlRange;
  13. If (document. body. createControlRange ){
  14. ControlRange = document. body. createControlRange ();
  15. ControlRange. addElement (div );
  16. ControlRange.exe cCommand ('copy ');
  17. }
  18. Div. contentEditable = 'false ';
  19. }
  20. </SCRIPT>
  21. </Head>
  22. <Body>
  23. <Div id = "divId1">
  24. </Div>
  25. </BODY>
  26. </Body>
  27. </Html>

Js to copy the database image to the clipboard

I have tried text placement, but I have never tried square images.

However, you can refer to js for reference ~, You can try it by yourself. If it succeeds, let me know.
<Script>
Function copyToClipboard ()
{
Var d = 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>

How to copy data to the clipboard using js?

I have tried text placement, but I have never tried square images.
However, you can refer to js for reference ~, You can try it by yourself. If it succeeds, let me know.
Script
Function copyToClipboard ()
{
Var d = 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.