Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

  1. #1
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Exclamation Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    Hello,
    I want to disable middle click default behaviour to do something else instead.
    In previous JQuery versions I was able to do this:

    Code:
    $('a').live('click',function (e) {
            alert(e.button)
            return false
    })
    With that code I was able to do something on middle clicks and also to disable the default behaviour.

    Now, with version 1.4.2 I can't do that any more.
    Using the 'mouseup' event I can get middle clicks but I can't disable the default behaviour.
    I have tried e.preventDefault() or binding both events: .live('click mouseup',etc) but nothing works.

    Thanks in advance!
    Last edited by Yuzem; March 31st, 2010 at 11:39 AM.

  2. #2
    Join Date
    Jan 2007
    Location
    Utah
    Beans
    550

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    I'm genuinely curious: why? Are you making some kind of game? If your web site is just a normal site, I would be very upset if you attempted to redefine my middle-click behavior. At that point, I'd probably blacklist your site in my JavaScript blocker to regain my freedom. It's not very wise to distort the "normal browsing experience".

    I cannot answer your question, though. I only use jquery for effects. I don't know much of the input API.

  3. #3
    Join Date
    Nov 2007
    Location
    Portugal
    Beans
    95
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    This may be a shot in the dark, but have you tried using "normal" click() event instead of the live()? Doesn't it work with that also?

    Can you give us an url to check what's happening to see if there's a better way to do it?

  4. #4
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    Quote Originally Posted by TheBuzzSaw View Post
    I'm genuinely curious: why?
    I'm coding an application that runs in prism: Figuritas
    On prism, it doesn't have the middle click problem but I want it to work on firefox also.

    Quote Originally Posted by enz1m3 View Post
    This may be a shot in the dark, but have you tried using "normal" click() event instead of the live()?
    I tried from firebug:
    Code:
    $('.tabs > .titles a')
    .die()
    .click(function ()
    {
        return false
    })
    ... but no luck.
    Quote Originally Posted by enz1m3 View Post
    Can you give us an url to check what's happening to see if there's a better way to do it?
    It isn't online but if you install the program you can go to: http://127.0.0.1:9009/
    If you middle click the first tab it opens in a new tab when it should do nothing.

  5. #5
    Join Date
    Nov 2007
    Location
    Portugal
    Beans
    95
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    ok, something is really wrong there, and it looks like you're not "pointing" to the right place.

    If you do:

    Code:
    $('.tabs > .titles a').click(function ()
    {
        alert('just a test');
    })
    Does the alert show after or before the new tab opens?

  6. #6
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    It doesn't show at all with middle clicks it only opens a new tab.
    With the following the alert shows before the new tab:
    Code:
    $('.tabs > .titles a').mouseup(function ()
    {
        alert('just a test');
    })

  7. #7
    Join Date
    Nov 2007
    Location
    Portugal
    Beans
    95
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    So I can suppose that code isn't simply executed... try to unbind() before the click() method... it should work that way.

    As for the the mouseup, if you change the alert to a return false or use the unbind() before the mouseup(), does it still work as expected (not opening the new tab)?

  8. #8
    Join Date
    Oct 2006
    Location
    Argentina
    Beans
    584
    Distro
    Ubuntu

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    Quote Originally Posted by enz1m3 View Post
    So I can suppose that code isn't simply executed... try to unbind() before the click() method... it should work that way.
    It doesn't work:
    Code:
    $('.tabs > .titles a')
    .unbind()
    .die()
    .click(function ()
    {
        alert('just a test');
    })
    On middle click it opens a new tab and the alert doesn't show.

    Quote Originally Posted by enz1m3 View Post
    As for the the mouseup, if you change the alert to a return false or use the unbind() before the mouseup(), does it still work as expected (not opening the new tab)?
    No, it still opens the new tab:
    Code:
    $('.tabs > .titles a')
    .unbind()
    .die()
    .mouseup(function ()
    {
        return false;
    })

  9. #9
    Join Date
    Nov 2007
    Location
    Portugal
    Beans
    95
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    Ok, use either unbind or die, don't use both, it's ambiguous.

    As for the code, that means the javascript for opening the tab is being done after.

    Try adding that jquery code on the end of the html file, right before the end of body tag.

  10. #10
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: Javascript / JQuery 1.4.2 - Disabling middle clicks on "a" tag

    Try using http://api.jquery.com/event.preventDefault/ instead of return false, may work for you

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •