JavaScript JS复制内容自动添加版权信息
function addLink() {
var body_element = document.body;
var selection;
var blogName = '你的网站名称';
selection = window.getSelection() ? window.getSelection() : document.selection.createRange().text;
if (window.clipboardData) {
var pagelink ="<br/>---------------------<br/>本文来源:"+blogName+"<br/>原文链接:"+document.location.href+"";
var copyText = selection + pagelink;
window.clipboardData.setData ("Text", copyText);
return false;
} else {
var pagelink = "<br/>---------------------<br/>本文来源:"+blogName+"<br/>原文链接:"+document.location.href+"";
var copyText = selection + pagelink;
var newDiv = document.createElement('div');
newDiv.style.position ='absolute';
newDiv.style.left ='-99999px';
body_element.appendChild(newDiv);
newDiv.innerHTML = copyText;
selection.selectAllChildren(newDiv);
window.setTimeout(function() {
body_element.removeChild(newDiv);
},0);
}
}
document.oncopy = addLink;
猜你喜欢:
暂无回复。