Home
User and System Preference
Here
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE5+ Opera7+
Disable Text Selection script Author:
Dynamic Drive
Note: Script rewritten Dec 28th, 06. Demo: Try selecting text within the above paragraph- it's disabled. Directions: Add this script to the HEAD section of your page: With the script installed, just call the function disableSelection(target) at the very end of the document with a reference to the element you wish to disable text within. A few examples:<script type="text/javascript"> disableSelection(document.body) //disable text selection on entire body of page </script> <script type="text/javascript">
var somediv=document.getElementById("mydiv")
disableSelection(somediv) //disable text selection within DIV with id="mydiv"
</script>
<script type="text/javascript">
var alltables=document.getElementsByTagName("table")
for (var i=0; i<alltables.length; i++)
disableSelection(alltables[i]) //disable text selection within all tables on the page
</script>
Make sure to call the above functions at the end of the document to ensure the element in which to disable text for is defined before the function is called.
|