javascript onselectstart Description

onselectstartNN n/a IE 4 DOM n/a  

Bubbles: Yes; Cancelable: Yes  

Fires immediately after the user begins dragging a selection on a body element or form control text. If the selection extends across multiple elements, only one event fires, and its target remains the element where the selection began. Canceling this event in the <body> tag (onselectstart="return false") can prevent undesirable and inadvertent user selection and scrolling interaction.

 
Typical Targets

All rendered elements.


  • #1
    2009-07-31
    [Quote]
    I am using 'onselectstart="return false"' in my body tag and it works elequently. However, I have a textbox (for searching) that I want the user to be able to select normally on. Is there a way to re-enable onselectstart for this one element?
  • javascript manual
    #2
    2009-08-03
    [Quote]
    [NETSECSVC: I am using 'onselectstart="return false"' in my body tag and it works elequently ...]

    Declare a variable say:
    var enableOnSelectEvent = true;

    On your <input>s add onmouseover and onmouseout events:
    enableOnSelectEvent = true/false;
    <body onselectstart="return !enableOnSelectEvent">

    It should work.
  • Greg
    #3
    2010-06-11
    [Quote]
    Trying it in Chrome on Windows, putting onselectstart="return true" in your textarea tag enables selecting in the textarea space, but leaves the rest of the body unselectable.
  • Greg
    #4
    2010-06-11
    [Quote]
    My mistake. Upon further investigation in Chrome, textareas are merely immune to this and the contents remain selectable.

    Meanwhile, I've found that SPAN elements won't implement it, but DIV elements will, BUT only to turn off selecting the contents of a DIV. If a DIVs parent element (BODY or another DIV) has selection turned off, you can't turn it on just in the DIV. But if selection is on, you can turn it off in specific DIV elements.
  • MyCodeAccount@yahoo.com
    #5
    2011-06-14
    [Quote]
    function prevent(e)
    { e=e||window.event
    s=e.srcElement||e.target
    s.onselectstartSaved=s.onselectStart
    s.onselectstart=null
    s.attachEvent('onmouseup',restore)
    }
    function restore(e)
    { e=window.event||e
    s=e.srcElement||e.target
    s.detachEvent('onmouseup',restore)
    s.onselectstart=s.onselectstartSaved }
NETSECSVC
javascript manual
Greg
MyCodeAccount@yahoo.com

1496,Nickname,Homepage or email,Comments here,Add comment