4

What i'm trying to accomplish works perfectly on Chrome -- Android 4.1 But fails pretty hard on iOS.

$(document).on('mouseenter touchend','[id*=mmlink]', function (e) {
    var $btn = $(this);
    var href = $btn.attr('href');
    var count = ($btn.data('click_count') || 0) + 1;

    $btn.data('click_count', count);
    if (count == 1) {  
        $btn.click(function(v) { 
            v.preventDefault();
        });
     } else {
        document.location.href = href;
     }
 });

I use milonic menu to generate sub menus. I need to use .on() to select the submenus.

test page: http://www.wolfbariatrics.com/mmtest/index.htm

I'm thinking there is another event that only happens in iOS. Remote Debugger for safari allows me to set breakpoints but as soon as I step in or over it follows the anchor tag.

I've gone as far as removing all events from the anchor tag entirely and the href but still nothing works.

palmplam
  • 707
  • 9
  • 20
Planet95
  • 41
  • 1
  • 1
  • 3
  • Are you using jQuery? Makes a big difference. – Zeno Popovici Oct 02 '12 at 19:07
  • yes i'm using jquery. http://jsfiddle.net/8AEHP/32/ i'm having trouble testing mobile browsers w/ jsfiddle... my test link works for me on multiple browsers and locations. – Planet95 Oct 02 '12 at 19:19
  • Any resolution for this? I am facing the same issue. Trying to prevent default Html5 date type handler to show my own calendar with a bunch of dates disabled from code. Safari mobile shows my calendar, but show its own also on top, and neither preventDefault nor return false; is able to block it.... Bizzarely it works fine in desktop mode, and on every other mobile browser I tried. – Drunken Code Monkey Sep 07 '21 at 14:30

1 Answers1

3

You might want to check this topic on StackOverflow about event.preventDefault and return false:

event.preventDefault() vs. return false

Basically: "jQuery's preventDefault does not prevent other handers from executing. That's what stopImmediatePropagation is for."

and

"return false from within a jQuery event handler is effectively the same as calling both e.preventDefault and e.stopPropagation on the passed jQuery.Event object.

e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both. Note that this behaviour differs from normal (non-jQuery) event handlers, in which, notably, return false does not stop the event from bubbling up. "

Community
  • 1
  • 1
Zeno Popovici
  • 589
  • 3
  • 15
  • I should of mentioned stopImmediatePropagation(); return false; stop(); and removing all events from the anchor tag have no effect. I can see the anchor tag being affected in the remote debugger but it doesn't affect the outcome on iOS. Works fine in android. – Planet95 Oct 02 '12 at 19:27
  • Can you setup a page that I can use with mobile Safari? The fiddle doesn't work very well. – Zeno Popovici Oct 02 '12 at 22:17