html复制网页内容,在后面添加版权信息
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
body{
text-align: center;
}
p{
width: 200px;
margin-top: 100px;
display: inline-block;
}
</style>
</head>
<body>
<p>啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦</p>
<script>
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/>原文链接:啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦";
var copyText = selection + pagelink;
window.clipboardData.setData ("Text", copyText);
return false;
} else {
var pagelink = "<br/>---------------------<br/>本文来源:"+blogName+"<br/>原文链接:啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦";
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;
</script>
</body>
</html>