www.webdeveloper.com
Results 1 to 3 of 3

Thread: Text selection disable & Opera Browser

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    13

    Text selection disable & Opera Browser

    While the script works fine on all browsers except Opera Browser. Input fields and drop down menu becomes unclickable, how to fix it?

    My example page:

    http://www.aymavisi.org/makale/Evlil...20Gibran).html

    Head:

    Code:
    <script type="text/javascript">
    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"
    }
    </script>

    Body:


    Code:
    <script type="text/javascript">
    disableSelection(document.body) 
    </script>
    
    <script type="text/javascript">
    var somediv=document.getElementById("layer1")
    disableSelection(somediv) 
    </script>
    P.S
    You can choose install Opera as portable in installation options.

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    target.onmousedown=function(){return false} is the source of the problem in Opera because it disables any mousedown event in the entire document.

    How about:

    target.onmousedown=function(){
    var txt=(window.getSelection)? window.getSelection().toString():document.selection.createRange().text;

    if(txt) return false;//if any text if selected
    }

  3. #3
    Join Date
    Nov 2011
    Posts
    13
    The modified script doesn't disable the text selection.
    Code:
    <script type="text/javascript">
    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(){
     var txt=(window.getSelection)? window.getSelection().toString():document.selection.createRange().text;
    
     if(txt) return false;//if any text if selected
     }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles