Friday, June 19, 2009

Disable right click to prevent page content

Some web developers and client want to disable the right click to prevent the theft their web content specially image. It can do by using a simple line of html code below though it can bypass in many ways.

<body oncontextmenu="return false;">

Update: I have got a best reference below:

No Right Click Script

Monday, June 1, 2009

Disable text selection on website by using javascript

Sometimes you may need to disable text selection of an HTML page. It is very easy way how you can do it. Below is the source codes:
<script type="text/javascript" language="JavaScript">
function disableText(e){
  return false;
function reEnable(){
  return true;
//For browser IE4+
document.onselectstart = new Function ("return false");

//For browser NS6
if (window.sidebar){
  document.onmousedown = disableText;
  document.onclick = reEnable;
Just copy the above JavaScript codes into your page under head section. Then whatever you write in your page everything will show in read-only mode.

Add following code to disable text selection on any key pressed:
window.onkeydown = disableText;
Add following code to disable text selection on ctrl key pressed:
window.onkeydown = function(e){
  if(e.ctrlKey == true){
    return false;

Click here to see the demo