You are here:   Articles
  |  Login

Programming Articles

Minimize
04

Here is some useful code to protect the content of your website from the average viewer who may casually try to grab it.

Of course, this will not prevent a determined person.

You can cut and paste all as is into your web page or just the parts you want to disable.

<script type="text/javascript">
//-----------------------------------------------------
// Disable select
document.onselectstart=new Function('return false');
function ffalse(e) {return false;}
function ftrue() { return true; }
document.onmousedown = ffalse;
document.onclick = ftrue;
//-----------------------------------------------------
// Disable right click
var message="You may not right click on this page.";
function noclick(e) {
  if (document.all) {
      if (event.button == 2) { alert(message); return false; } }
  if (document.layers) {
        if (e.which == 3) { alert(message); return false; } }
  }
if (document.layers) { document.captureEvents(Event.MOUSEDOWN); }
// Override what was sent under disable select above
document.onmousedown=noclick;
//-----------------------------------------------------
</script>
<style type="text/css">
/* disable print */
@media print {body {display:none;}}
</style>

Some browsers let users drag click on an image and then drag the image to their desktop. To prevent image dragging you can add this code to each image.

<img src="image.png"
onmousedown="if (event.preventDefault) event.preventDefault()"
>

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter



Reccomend Programmer.bz

Minimize

Share/Bookmark Bookmark and Share