Home > Web Front-end > JS Tutorial > Detailed analysis of js clipboard application clipboardData_javascript skills

Detailed analysis of js clipboard application clipboardData_javascript skills

WBOY
Release: 2016-05-16 17:08:41
Original
1311 people have browsed it

注意:ie7,与ie8 对网页有个复制的权限,需在“安全”中的“自定义级别”的脚本中设置

clipboardData 对象

提供了对剪贴板的访问。

三个方法
1.clearData(sDataFormat) 删除剪贴板中指定格式的数据。
2.getData(sDataFormat) 从剪贴板获取指定格式的数据。
3.setData(sDataFormat, sData) 给剪贴板赋予指定格式的数据。返回 true 表示操作成功。

例子

一些方法:





Js复制代码




  




直接复制url






点击文本框时,复制文本框里面的内容






复制文本框或者隐藏域中的内容








复制span标记中的内容





The following is the code snippet: <br />


http: //pmp.www.jb51.net
[Click to copy]


http://www.www.jb51.net/pmp
[Click to copy]



There is another way:

function copyQQ(qq){
var obj=document.getElementById(qq);
obj.select();
js=obj.createTextRange();
js.execCommand(" Copy");
alert("The code has been copied successfully!");

}


//Set the copied content and attach the URL of this website
        function SetCopyContent() {
              window.event.returnValue = false; ;
content = document.getElementById("txt1").value "/r/n";
content = "This resource comes from" this.location.href;
window.clipboardData.setData('Text ', content);
alert("Copied successfully, please paste it into your QQ/MSN to recommend to your friends");
}

Call:



Copy code The code is as follows:



Window object Attribute 02





안녕하세요 MyJSWorld!







Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template