文章被复制时自动加入版权信息(文字水印)的两种方法
方法一、[code]<script type="text/javascript">document.body.oncopy = function () {
setTimeout( function () { G}4C3X@~&j2Y,w1~ Ep
var text = clipboardData.getData("text");gQ&t0{O0n5_
if (text) {
text = text + "\r\n 【温馨提示】本文转载自: "+location.href; clipboardData.setData("text", text);+_Xr tW:wy(jvdI
}
}, 100 ) 9MaJ*R9s9@^
}u'Q;kL:zbh
</script>[/code]测试结果: Maxthon下不弹出提示,IE7和IE6下会弹出提示。Firefox下无效。
方法二、[code]<script type="text/javascript">
document.body.oncopy = function() {#|X"M-N%nPsRr G
event.returnValue = false;
var t = document.selection.createRange().text;^:spF(ia,m
var s = "【温馨提示】本文转载自: "+top.window.location.href;
clipboardData.setData('Text',t+'\r\n'+s+'\r\n\r\n\r\n');
}})~P5Z/DV
</script>[/code]测试结果: Maxthon和IE7下不弹出提示,IE6下会弹出提示。Firefox下无效。
页:
[1]