Đoạn mã chống copy bài viết và hình ảnh
-
H Ngoại tuyếnToa 1
Để hạn chế người dùng copy dữ liệu từ diễn đàn, website bạn có rất nhiều cách. Dưới đây là một cách. Hãy chèn đoạn mã dưới vào website bạn muốn bảo vệ. Sẽ hạn chế khi người dùng view source , copy bài viết, hình ảnh ...
<script language="JavaScript1.2">
var message="Text Here";
function click(e)
{
if (document.all)
{
if (event.button==2||event.button==3)
{
alert(message);
return false;
}
}
else
{
if (e.button==2||e.button==4)
{
e.preventDefault();
e.stopPropagation();
alert(message);
return false;
}
}
}
if (document.all) // for IE
{
document.onmousedown=click;
}
else // for FF
{
document.onclick=click;
}
</script>
<script type="text/javascript">
function ehan( evnt )
{
if( evnt.which == 3 )
{
alert( "Text Here" );
return false;
}
return true;
}
function ocmh()
{
alert( "Text Here" );
return false;
}
document.oncontextmenu = ocmh;
document.captureEvents( Event.MOUSEDOWN );
if( document.layers ) document.onmousedown = ehan;
</script>
<SCRIPT language="JavaScript">
if (window!=top){top.location.href=location.href;}
</script>
<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><SCRIPT language="JavaScript">if (window!=top){top.location.href=location.href;}
</script>
<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> -
G Ngoại tuyếnToa 2
Mình bổ sung thêm mấy cái nữa
- Đoạn mã hạn chế người khác Save As.. trang web
<noscript><iframe src=*.html></iframe></noscript>- Hạn chế select text
<script language=JavaScript1.2>
function disableselect(e){
return false
}function reEnable(){
return true
}//if IE4+
document.onselectstart=new Function ("return false")//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>- Khóa chuột phải (hạn chế view link nhạc, copy hình ảnh...)
<script language=JavaScript>
var msg="Welcome to Đà Lạt Hoa Com";
function disableIE() {if (document.all) {alert(msg);return false;}
}
function disableNS(e) {
if (document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {alert(msg);return false;}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=disableNS;
} else {
document.onmouseup=disableNS;document.oncontextmenu=disableIE;
}
document.oncontextmenu=new Function("alert(msg);return false")
</script>