js点击后将文字复制到剪贴板,将图片复制到画图
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JScript">
var oPopup = window.createPopup();
function ButtonClick(div)
{
//var div = document.getElementById('divId');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}
</SCRIPT>
</head>
<body>
<div id="divId1">
<img src="http://avatar.csdn.net/5/1/D/1_yy_2011.jpg" onclick="ButtonClick(this)">
</div>
</BODY>
</body>
</HTML>
复制文字:
- <table width="99%" border="0" cellpadding="0" cellspacing="0" class="firtable">
- <tr>
- <th width="100%" style="color: white;"><s:text name="询单明细"></s:text></th>
- </tr>
- <tr>
- <td align="center">
- <textarea name="inquiryContact1" id="inquiryContact1" rows="15" cols="60" readonly="readonly"></textarea>
- <div id="inquiryInfoDIV" style="display:none">
- <s:property value="inquiryContact" escape="false"/>
- </div>
- <script> dojo.byId("inquiryContact1").innerText=dojo.byId("inquiryInfoDIV").innerText;
- </script>
- </td> </tr>
- <tr>
- <td align="center">
- <input type="button" id="button" name="button" value="复制" onclick="copyContact()"/>
- </td> </tr> </table>
- <script type="text/javascript">
- var i = 0 ;
- function copyContact(){
- var contat = document.getElementById("inquiryContact1").value;
- window.clipboardData.setData('text', contat);
- if(window.clipboardData.getData('text')==''){
- if(i==1){
- alert("复制失败,请手动Ctrl+C快捷键复制!");
- }else{
- alert("复制失败,请重新复制!");
- i = 1;
- }
- }else{
- alert("内容已经复制到剪贴板!");
- }
- }
- </script>
复制图片:
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- <SCRIPT LANGUAGE="JScript">
- var oPopup = window.createPopup();
- function ButtonClick(div)
- {
- //var div = document.getElementById('divId');
- div.contentEditable = 'true';
- var controlRange;
- if (document.body.createControlRange) {
- controlRange = document.body.createControlRange();
- controlRange.addElement(div);
- controlRange.execCommand('Copy');
- }
- div.contentEditable = 'false';
- }
- </SCRIPT>
- </head>
- <body>
- <div id="divId1">
- <img src="F:/2012070518474964.jpg" onclick="ButtonClick(this)">
- </div>
- </BODY>
- </body>
- </html>
复制文字:
- <table width="99%" border="0" cellpadding="0" cellspacing="0" class="firtable">
- <tr>
- <th width="100%" style="color: white;"><s:text name="询单明细"></s:text></th>
- </tr>
- <tr>
- <td align="center">
- <textarea name="inquiryContact1" id="inquiryContact1" rows="15" cols="60" readonly="readonly"></textarea>
- <div id="inquiryInfoDIV" style="display:none">
- <s:property value="inquiryContact" escape="false"/>
- </div>
- <script> dojo.byId("inquiryContact1").innerText=dojo.byId("inquiryInfoDIV").innerText;
- </script>
- </td> </tr>
- <tr>
- <td align="center">
- <input type="button" id="button" name="button" value="复制" onclick="copyContact()"/>
- </td> </tr> </table>
- <script type="text/javascript">
- var i = 0 ;
- function copyContact(){
- var contat = document.getElementById("inquiryContact1").value;
- window.clipboardData.setData('text', contat);
- if(window.clipboardData.getData('text')==''){
- if(i==1){
- alert("复制失败,请手动Ctrl+C快捷键复制!");
- }else{
- alert("复制失败,请重新复制!");
- i = 1;
- }
- }else{
- alert("内容已经复制到剪贴板!");
- }
- }
- </script>
复制图片:
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- <SCRIPT LANGUAGE="JScript">
- var oPopup = window.createPopup();
- function ButtonClick(div)
- {
- //var div = document.getElementById('divId');
- div.contentEditable = 'true';
- var controlRange;
- if (document.body.createControlRange) {
- controlRange = document.body.createControlRange();
- controlRange.addElement(div);
- controlRange.execCommand('Copy');
- }
- div.contentEditable = 'false';
- }
- </SCRIPT>
- </head>
- <body>
- <div id="divId1">
- <img src="F:/2012070518474964.jpg" onclick="ButtonClick(this)">
- </div>
- </BODY>
- </body>
- </html>