现在的网站每天增长数量达到千万个,但是这些网站中90%的确是些垃圾站,要么没有实质性的内容,要么直接自动采集别人网站的内容。所以,往往原创者的一片文章或是创新内容在发布不久就会有N个复制的版本,实在是对不起原创的作者。那么,今天就为大家分享解决这个问题的方法之一:用JS实现防止网站内容被别人复制的功能。
首先需要在页面body中加入下面的代码:
<body oncontextmenu="return false" onselectstart="return false" oncopy="return false">
然后下面是哥哥功能的函数块:
1、禁止鼠标右键
$(document).bind("contextmenu", function(e) {
return false;
});
2、禁止键盘按键:
<script type="text/javascript">
function key() {
if (event.shiftKey) {
window.close();
}
//禁止Shift
if (event.altKey) {
window.close();
}
//禁止Alt
if (event.ctrlKey) {
window.close();
}
//禁止Ctrl
return false;
}
document.onkeydown = key;
</script>
3、禁止选中内容
<script type="text/javascript">
var omitformtags = ["input", "textarea", "select"]
omitformtags = omitformtags.join("|")
function disableselect(e) {
if (omitformtags.indexOf(e.target.tagName.toLowerCase()) == -1)
return false
}
function reEnable() {
return true
}
if (typeof document.onselectstart != "undefined")
document.onselectstart = new Function("return false")
else {
document.onmousedown = disableselect
document.onmouseup = reEnable
}
</script>
4、禁止网页另存为
<noscript>
<iframe src="/*"></iframe>
</noscript>
当然,还有其他的方法可以实现。例如还有另外一种方法,除了禁止另存外其它功能基本上能够实现,代码如下(直接加在body标签里即可):
<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
