document.selection.empty()

D

David

Is there a way to achieve in Firefox (and other browsers) what I achieve in
IE6 with the document.selection.empty()? I want to be able to empty the
selection every time the user clicks a certain area, thus making it
impossible to select any text in that area. Is there a way to clear the
text selection in Firefox?

David
 
M

Martin Honnen

David wrote:

I want to be able to empty the
selection every time the user clicks a certain area, thus making it
impossible to select any text in that area.

Well JavaScript in the DOM mostly works on elements and other nodes and
not on "areas" but if you for instance have a <div> element and you want
to prevent that the user selects text inside the <div> element then you
can do that with
<div onselectstart="return false;"
style="-moz-user-select: none;">
<p>Kibology for all.</p>
<p>All for Kibology.</p>
</div>
for IE (with the onselectstart="return false;") and for Mozilla (with
the CSS extension -moz-user-select: none;).
There is no need to try to manipulate/empty the selection with script.
 
C

Christopher Benson-Manica

Martin Honnen said:
<div onselectstart="return false;"
style="-moz-user-select: none;">

As chance would have it, I had been wanting to do this very thing as
well, and now I can - thank you!
 
D

David

Martin said:
Well JavaScript in the DOM mostly works on elements and other nodes and
not on "areas" but if you for instance have a <div> element and you want
to prevent that the user selects text inside the <div> element then you
can do that with
<div onselectstart="return false;"
style="-moz-user-select: none;">
<p>Kibology for all.</p>
<p>All for Kibology.</p>
</div>
for IE (with the onselectstart="return false;") and for Mozilla (with the
CSS extension -moz-user-select: none;).
There is no need to try to manipulate/empty the selection with script.

Ahh, very simple and it does just what I'm wanting, thanks a lot!!

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top