Este exemplo de artigo descreve o método de copiar texto ou imagens para a área de transferência depois de clicar por JS. O código é muito conciso e prático, e o código de função específico é o seguinte:
Implementar o código de texto de cópia:
<tabela CellPadding = "0" CellPacing = "0"> <tr> <th style = "cor: white;"> <s: name de texto = "Querylist Detalhes"> </s: text> </th> </tr> <tr> <td align = "center"> <textarea = "inquiryContact1" ids = "Inquiryc. readOnly = "readonly"> </sexttarea> <div id = "inquieryinfodiv" style = "display: none"> <s: property value = "ingressyContact" escape = "false"/> </div> <cript> dojo.byid ("innchiryContact1") .erTextText = doJO.InID ("; </script> </td> </tr> <tr> <td align = "center"> <input type = "button" id = "button" name = "button" value = "copy" onclick = "copycontact ()"/> </td> </tr> </tabela <script type = "text/javascript"> var i = 0; function copycOntact () {var contat = document.getElementById ("InquiryContact1"). window.clipboarddata.setData ('texto', contat); if (window.clipboarddata.getdata ('text') == '') {if (i == 1) {alert ("cópia falhou, copie manualmente Ctrl+C Tecla de atalho!"); } else {alert ("cópia falhou, copie novamente!"); i = 1; }} else {alert ("O conteúdo foi copiado para a área de transferência!"); }} </script>Implementar o código da imagem de cópia:
<! Doctype html public "-// w3c // dtd html 4.01 transitória // pt" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv = contentnppe " <TITLE> Insira o título aqui </itit> <script idioma = "jscript"> var opopup = window.createPopup (); função buttonClick (div) {// var div = document.getElementById ('divid'); div.contentitable = 'true'; VAR ControlRange; if (document.body.createControlRange) {controlRange = document.body.createControlRange (); ControlRange.adDelement (div); controlRange.execCommand ('cópia'); } div.contentitable = 'false'; } </Script> </head> <body> <div id = "divid1"> <img src = "f: /2012070518474964.jpg" onclick = "buttonClick (this)"> </div> </body> </body> </html>Os leitores interessados podem testar o código ou modificar e melhorar suas funções!