9

In a jquery-mobile based web app, how do i prevent the default browser menu from showing on "tap hold" .. instead i want to show a custom dialog page ..

mentioned below is my code as of now ..

$(".task_row").bind('taphold',function(event, ui){
    event.preventDefault();
    $("#slide_down_menu").trigger('click');
});
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
Abhishek Jain
  • 971
  • 3
  • 13
  • 18
  • 3
    are you sure it's not a rightclick menu? what browser? try listening to `contextmenu` event and `.preventDefault();return false;` on it – naugtur May 04 '11 at 11:26
  • if I understand correctly, @naugtur suggests the solution as described here: https://stackoverflow.com/questions/30775237/disable-taphold-default-event-cross-device Worked in all my cases with touch devices – gaugau Nov 16 '18 at 18:30

6 Answers6

11

use css:

a {
    -webkit-touch-callout: none !important; 
}

to not show the standard dialog

axel wolf
  • 1,446
  • 3
  • 18
  • 29
2

The trouble is that the 'taphold' event that you are binding to is a custom event that is triggered by jQuery Mobile, so it is not the same event that triggers the browser's default behavior.

If the default menu you are trying to avoid is the one that allows you to "Open" or "Copy" the url, then one solution is to not use an <a> tag. If you use a span or a div, you can bind an ontap function to it that will change the browser's location, and your taphold event will not be interrupted with the default behavior.

j0k
  • 22,600
  • 28
  • 79
  • 90
mishka
  • 31
  • 3
1

I found out you have to disable right-clicking.

$(function(){

    document.oncontextmenu = function() {return false;};

    $(document).mousedown(function(e){

        if ( e.button == 2 )
        { 
            alert('Right mouse button!'); 
            return false; 
        }

        return true;
    });
});
bafromca
  • 1,926
  • 4
  • 27
  • 42
0

What about using the ontouchstart event? I'm pretty sure I've used this to prevent the default iPad interactions from occuring.

$(".task_row").bind('touchstart', function(event, ui){
    event.preventDefault();
    $("#slide_down_menu").trigger('click');
});
Simon East
  • 55,742
  • 17
  • 139
  • 133
0

You were pretty close with it. The correct code is:

$('#ciytList li a ').bind('taphold', function(e) {
    e.preventDefault();
    return false;
} );
0

I just took off the link and applied css to make it look like one and used this

$.mobile.changePage( "#main", { transition: "slideup"} );

but i already had it bound to a click event that shows a delete button... no more popup menu

Roger Large
  • 105
  • 12