Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: Disable Text Select

Tags:

javascript

I'm using javascript to disable text selection on my webiste.

The code is:

<script type="text/JavaScript">  function disableselect(e) {   return false }  function reEnable() {   return true }  document.onselectstart = new Function ("return false")  if (window.sidebar) {   document.onmousedown = disableselect   document.onclick = reEnable } </script> 

Similar script can be found here

On my localhost: All Browsers (Firefox, Chrome, IE and Safari) work great.

On my Live site: All ok EXCEPT Firefox.

My questions are:

  1. Does anyone have a suggestion as to why Firefox behaves differently for the live site and local host. Note: Javascript is enabled.

  2. Maybe my script is too simplistic so I've tried the following with EXACTLY SAME Results

like image 890
arpeggio Avatar asked May 29 '13 04:05

arpeggio


People also ask

How do I turn off select text?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I remove text from a selection in CSS?

Use the user-select: none; CSS rule.


1 Answers

Just use this css method:

body{     -webkit-touch-callout: none;     -webkit-user-select: none;     -khtml-user-select: none;     -moz-user-select: none;     -ms-user-select: none;     user-select: none; } 

You can find the same answer here: How to disable text selection highlighting using CSS?

like image 123
Zachrip Avatar answered Sep 25 '22 20:09

Zachrip