Results 1 to 5 of 5

Thread: disabling middle mouse botton for combobox

  1. #1
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default disabling middle mouse botton for combobox

    Hi.
    How can I disable middle mouse button for scrolling on a combobox?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In IE and Opera:

    Code:
    <select id="bob" size="6" onmousewheel="return false;">
    Capturing the middle mouse button for the purpose of disabling it can be done, somewhat. But, I haven't seen any reliable cross browser method. It also may depend (in this case) upon the layout, other scripts (if any) and exactly why you need this. Any javascript solution will not work if javascript is disabled. Also, it might be better to capture and use the middle mouse button rather than disabling it.

    In short, if you can find a way to not need to disable it, even to not need to capture it, that would be best as, the cross browser support on this one is thin.
    Last edited by jscheuer1; 02-05-2007 at 05:51 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I looked into this a bit more, and this seems pretty reliable:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Kill Wheel on Selects - Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function ffkillwheel(el){
    if(el.addEventListener&&!el.onmousewheel)
    el.addEventListener('DOMMouseScroll', killwheel, false);
    }
    function killwheel(e){
    var e=e? e : window.event;
    if (e.preventDefault)
    e.preventDefault();
    e.returnValue = false;
    return false;
    }
    </script>
    </head>
    <body>
    <select size="6" onmouseover="ffkillwheel(this);" onmousewheel="killwheel()">
    <option value="">ffffffffffff</option>
    <option value="">ggggggggfffffff</option>
    <option value="">ddddddddddfffffff</option>
    <option value="">rrrrrrrrrrrr</option>
    <option value="">xxxxxxxxffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    <option value="">ffffffffffff</option>
    </select>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Why do you want to disable the middle mouse button? I think you would be much farther ahead to avoid a situation where that is necessary.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by blm126 View Post
    Why do you want to disable the middle mouse button? I think you would be much farther ahead to avoid a situation where that is necessary.
    That was my initial reaction as well. However, since someone asked me a little while back to make up simultaneous scrolling divisions I noticed there are times that one doesn't want the mouse wheel involved.

    The real problem is that the mousewheel's brand of scrolling often, if not always, doesn't change the scrollTop position of the element being scrolled. If your script works off of that value, it will break when the user scrolls your element with the mousewheel.

    Interestingly, while researching the code I posted for this solution I discovered a routine that will capture the event for use by other code. Ultimately this might be the way to go with scripting the mousewheel. Since its direction and possibly travel can be captured, the wheel event could be made to power a scroll event, thus making the wheel compatible with the scrollTop value once again. I'm not certain that the travel can be captured but, a reasonable value probably could be assigned and used.

    For more on how this might be done, see:

    http://adomas.org/javascript-mouse-wheel/
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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