Restricting user not to select Webpage data

Some times we need to restrict user not to select form/Webpage data, it can be done by using below code :

<html>
<head>
<script type=”text/javascript”>
function disableSelection(target)
{
if (typeof target.onselectstart!=”undefined”) //IE
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!=”undefined”) //Firefox
target.style.MozUserSelect=”none”
else //All other (ie: Opera)
target.onmousedown=function(){return false
}
target.style.cursor = “default”
}
</script>
</head>
<body>
<h1> Testing code for user not to select form data</h1>
<br>
<p>
In object-oriented programming (OOP), Inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called

objects which can be based on previously created objects. In classical inheritance where objects are defined by classes, classes can inherit other classes.

The new classes, known as Sub-classes (or derived classes), inherit attributes and behavior of the pre-existing classes, which are referred to as

Super-classes (or ancestor classes). The inheritance relationship of sub- and superclasses gives rise to a hierarchy. In Prototype-based programming objects

can be defined directly from other objects without the need to define any classes.
</p>
<script type=”text/javascript”>
disableSelection(document.body) //disable text selection on entire body of page
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById(“mydiv”)) //Disable text selection on element with id=”mydiv”
</script>
</body>
</html>

Advertisements