如何通过javascript复制图片到剪贴板?高分求解决方案 好像不行吧 只能图片的url吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <body id="www.never-online.net"> <script type="text/javascript"> //<![CDATA[ function copyEventHandler() { var x=document; var r=x.selection.createRange(); x.execCommand("Copy"); } //]]> </script> 选中图片,点COPY <input onclick="copyEventHandler()" type="button" value="COPY"/> <img src="http://zi.csdn.net/760-90netbeans-video_2.gif"/> </body> 上面的方法复制下来的只是图片的url,若想获得图片,就得用流来读取文件. 楼上,你先试试再说,看看是图片,还是URL,COPY后paste到你的word..:D BlueDestiny 的方法试过了也不行, 如果要实现复制图片到剪切板那么复制的其实应该是IE临时文件夹里面的图片文件,可是由于安全限制JS又无法操作本地文件,这似乎真的是无法完成的任务 execCommand->>MS IE ONLY 怎么会没有效果??看下面...<body id="www.never-online.net"> <script type="text/javascript"> //<![CDATA[ onload = function () { var x; x=document.getElementById("p").contentWindow.document x.open(); x.write("<body contentEditable=true>"); x.close(); window.clipboardData.clearData(); } function copyEventHandler() { var x=document; var r=x.selection.createRange(); x.execCommand("Copy"); x=document.getElementById("p").contentWindow.document; x.selection.createRange();x.body.focus(); x.execCommand("Paste"); } //]]> </script> <img src="http://zi.csdn.net/760-90netbeans-video_2.gif"/><br/> 选中图片,点COPY<br/> <input onclick="copyEventHandler()" type="button" value="COPY"/> 下面的iframe是Paste后的效果<br/> <iframe id="p"></iframe> </body> TO BlueDestiny 我想这复制的只是选中的HTML代码吧?我需要达到的是复制图片,然后可以把图片粘贴到画图工具里面去的 可以实现,不过只有IE有效。看下面代码:html:<img src="xxxxx/null.gif" width="0" height="0" id="10008"><div class="padding5"><input type="button" class="ctrlc" value="复制到QQ" alt="10008"></div>js: var $copy = document.body.createControlRange();$(".ctrlc").click(function(){ //var $img = new Image(); var $id = $(this).attr("alt"); var $src = $(".picture").attr("src"); $("#" + $id).attr("src",$src); var $this = document.getElementById($(this).attr("alt")); if ($this.tagName != 'IMG') return; if (typeof $this.contentEditable == "undefined") return; if (!document.body.createControlRange) return; $this.contentEditable = true; $copy.addElement($this); $copy.execCommand("Copy"); $this.contentEditable = false; alert("复制完成,请在QQ聊天对话框里按Ctrl+V(或点右键后在出现的菜单中点粘贴)然后发图!");}); 模式对话框 在网站中加入地图,哪个地图更好? Google地图?百度地图?... hookee 回复于:2009-09-30 的新问题! 散分, 成功转型AS3开发... js列求和问题,希望大家帮忙解决 再散一贴 asp.net的问题需要用JS来解决,所以就来这里啊,大家要帮忙哦~~~~~ Hidden 控件的使用问题! 求大牛给个说法! datatable meta: 为一个子对象,包含3个属性 row: 当前行的索引 获取索引怎么写 如何改变IFRAME显示出来之前,该区域的背景色。 firefox不支持sessionStorage?
<script type="text/javascript">
//<![CDATA[
function copyEventHandler() {
var x=document;
var r=x.selection.createRange();
x.execCommand("Copy");
}
//]]>
</script>
选中图片,点COPY
<input onclick="copyEventHandler()" type="button" value="COPY"/>
<img src="http://zi.csdn.net/760-90netbeans-video_2.gif"/>
</body>
<body id="www.never-online.net">
<script type="text/javascript">
//<![CDATA[
onload = function () {
var x;
x=document.getElementById("p").contentWindow.document
x.open();
x.write("<body contentEditable=true>");
x.close();
window.clipboardData.clearData();
}
function copyEventHandler() {
var x=document;
var r=x.selection.createRange();
x.execCommand("Copy");
x=document.getElementById("p").contentWindow.document;
x.selection.createRange();x.body.focus();
x.execCommand("Paste");
}
//]]>
</script> <img src="http://zi.csdn.net/760-90netbeans-video_2.gif"/><br/>
选中图片,点COPY<br/>
<input onclick="copyEventHandler()" type="button" value="COPY"/> 下面的iframe是Paste后的效果<br/>
<iframe id="p"></iframe>
</body>
我需要达到的是复制图片,然后可以把图片粘贴到画图工具里面去的
html:<img src="xxxxx/null.gif" width="0" height="0" id="10008">
<div class="padding5"><input type="button" class="ctrlc" value="复制到QQ" alt="10008"></div>
js: var $copy = document.body.createControlRange();
$(".ctrlc").click(function(){
//var $img = new Image();
var $id = $(this).attr("alt");
var $src = $(".picture").attr("src");
$("#" + $id).attr("src",$src); var $this = document.getElementById($(this).attr("alt")); if ($this.tagName != 'IMG')
return; if (typeof $this.contentEditable == "undefined")
return; if (!document.body.createControlRange)
return; $this.contentEditable = true;
$copy.addElement($this);
$copy.execCommand("Copy");
$this.contentEditable = false;
alert("复制完成,请在QQ聊天对话框里按Ctrl+V(或点右键后在出现的菜单中点粘贴)然后发图!");});