Farhan411, Mobile# +92344-4774321
Main
Registration
Login
Saturday
2010-03-20
1:27 Am
Welcome Guest | RSS
Farhan Khalid
  • Register
  • Login form
    E-mail:
    Password:

    [ New messages · Members · Forum rules · Search · RSS ]
    Page 1 of 11
    Forum » Education Club » Javascript » Disable Text Selection script
    Disable Text Selection script
    farhan411Date: Friday, 2009-05-08, 10:05 PM | Message # 1
    Admin
    Group: Administrators
    Messages: 284
    Awards: 0
    Awards: 0
    Reputation: 0
    Status: Offline
    Disable Text Selection script

    Author: Dynamic Drive

    Note: Script rewritten Dec 28th, 06.

    Description: This is a simple script that lets you disable text selection (the ability to drag and select text) within any element on your page, such as a certain paragraph. Script works in IE, Firefox, and Opera.

    Demo: Try selecting text within the above paragraph- it's disabled.

    Directions: Add this script to the HEAD section of your page:
    Available for users only

    Code

    <script type="text/javascript"> /*********************************************** * Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ function disableSelection(target){ if (typeof target.onselectstart!="undefined") //IE route target.onselectstart=function(){return false} else if (typeof target.style.MozUserSelect!="undefined") //Firefox route target.style.MozUserSelect="none" else //All other route (ie: Opera) target.onmousedown=function(){return false} target.style.cursor = "default" } //Sample usages //disableSelection(document.body) //Disable text selection on entire body //disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv" </script>

    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:
    Available for users only
    [/code]


    [code]

    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. :new:[code]
    HTML code to this post
    BB-code to this post
    Direct link to this post


    Message edited by farhan411 - Friday, 2009-05-08, 10:10 PM
     
    Forum » Education Club » Javascript » Disable Text Selection script
    Page 1 of 11
    Search:

    Statistics Forum
    Recent Posts Readable topic Top Users New User
    Farhan411 www.farhan411.do.am www.elite411.forum.st elite411
    Copyrights www.Farhan411.do.am © 2010
    Hosted by uCoz