您当前的位置:KKBlog > 学无止境 > WEB前端

JS复制页面文字时,在文字后面增加 附加信息

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>复制页面文字时,增加“附加信息[url]www.jianfangkk.com[/url]</title>
 
</head>
 
<body>
将这段文字复制后,在其他地方粘贴你就能看到自动加入的文字
<script type="text/javascript">
document.body.oncopy = function () { 
 setTimeout( function () { 
   var text = clipboardData.getData("text"); 
   if (text) { 
    text = text + "本文来自-- [url]www.jianfangkk.com[/url]"; 
    clipboardData.setData("text", text); 
   } 
 }, 100 ) 
}
</script>
</body>
</html>


二维码
意见反馈 二维码