js监听浏览器剪贴板
function setClipboardText(event){ event.preventDefault(); var node = document.createElement('div'); node.innerHTML= window.getSelection(0).toString(); var result = window.getSelection(0).toString(); if (result.length>51){ result=result.substring(0,50); } var htmlData = '<div>此版权归所XXXXX所有。<br />' + '如有它用请联系XXXXXXX获得授权。<br />' + '来源:XXXXXXXX<br /><br />' + '每次复制最多50个字<br /><br />' + result + '</div>'; var textData = '此版权归所XXXXXX所有。\n' + '如有它用请联系XXXXXXXX获得授权。\n' + '每次复制最多50个字\n' + result; if(event.clipboardData){ event.clipboardData.setData("text/html", htmlData); event.clipboardData.setData('text/plain', textData); } else if(window.clipboardData){ return window.clipboardData.setData("text", textData); } }; document.addEventListener('copy', function(event){ setClipboardText(event); });