document.addEventListener('copy', function (event) {
var clipboardData = event.clipboardData || window.clipboardData;
if (!clipboardData) { return; }
var text = window.getSelection().toString();
if (text) { event.preventDefault();
clipboardData.setData('text/html', text.replace(/\r\n/g,"
").replace(/\n/g,"
").replace(/
/g,"
\r\n") + '
\r\n中文静网,浏览器自动缓存,断网可用,全静态托管,速度快。
\r\n本文链接:[url=]' +window.location.href+'[/url]');
clipboardData.setData('text/plain', text.replace(/\r\n/g,"
").replace(/\n/g,"
").replace(/
/g,"\r\n")+ '\r\n中文静网(cnj8.com),浏览器自动缓存,断网可用,全静态托管,速度快。\r\n本文链接:' +window.location.href);
}
})
总结:这个版本优化了很多次,终于让自己满意了,故分享给大家,希望对大家有所启示