Javascript Reference
Categories: onselectstart

javascript onselectstart Description

@March 15, 2008, 1:22 a.m.
onselectstartFirefox/Netscape/NN n/a IE 4 Chrome/Safari/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.

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 }
MyCodeAccount@yahoo.com - 2011-06-14
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.
Greg - 2010-06-12
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 - 2010-06-12

Powered by Linode.