Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

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

  1. #11
    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
    Try adding that jquery code on the end of the html file, right before the end of body tag.
    I tried, the result is exactly the same, same order, first the alert and then the new tab.

    Quote Originally Posted by AlexC_ View Post
    Try using http://api.jquery.com/event.preventDefault/ instead of return false, may work for you
    I have tried:
    .preventDefault()
    .stopImmediatePropagation()
    .stopPropagation()
    Nothing work...
    I have tried linking the events to a parent and then detecting the target with e.target.nodeName using .stopPropagation and all the others but nothing works.

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

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

    Quote Originally Posted by Yuzem View Post
    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.
    Ah, that makes more sense. Cool!
    Code:
    while (homework > 0) happiness--;
    // Don't worry. I'm a multithreaded program. ;)

  3. #13
    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...

    Can you please try and create a simple html file online only with a link and disabling the middle click like you do (to be sure it's a jQuery 1.4 thing and not some kind of overwrite/incompatibility in your code)?

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

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

    I tried that and the problem persist.
    Here is the source:
    Code:
    <html>
    	<head>
    		<script src="web/jquery.js" type="text/javascript"></script>
    	</head>
    	<body>
    		<a href="http://google.com">click here</a>
    		<script type="text/javascript">
    			$("a")
    				.unbind()
    				.mouseup(function ()
    				{
    					e.preventDefault()
    					alert("Hello");
    					return false;
    				})
    		</script>
    	</body>
    </html>

  5. #15
    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, I was finally able to disable middle-click, but I had to call the bind on the document, not the specific element, so you may need to improve the middle-button click check.

    Check out http://www.brunobernardino.com/midclick.html

    EDIT: Just in case I remove that file accidentally

    Code:
    <html>
    	<head>
    		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    	</head>
    	<body>
    		<a href="http://google.com">click here</a>
    		<script type="text/javascript">
    		$(document).ready(function() {
    			$("a").bind("click",function(e) {
    				alert("e = " + e.button);
    			});
    			$(document).bind("click",function(e){
    				if (e.button == 1) {
    					e.preventDefault();
    					return false;
    				}
    			});
    		});
    		</script>
    	</body>
    
    </html>
    Last edited by enz1m3; March 30th, 2010 at 11:15 PM. Reason: Just in case I remove that file accidentally

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

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

    Ok, that worked. I will use: e.target.nodeName
    Thank you very much!

  7. #17
    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

    Please add [SOLVED] to the topic (first post)

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

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

    Done.
    Any idea on why it isn't working on the a tag?

  9. #19
    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

    Well, I'd say it makes sense if Firefox binds those browser behaviors to the document element and then checks after the event, what's the target, so applying the behavior to an element inside the document wouldn't unbind the default behaviors, but I'm just speculating

Page 2 of 2 FirstFirst 12

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
  •