For a website I want to show a custom context menu when a user "longpresses" the screen. I've created a jQuery Longclick listener in my code to show a custom context menu. The context menu is displayed, but the iPad's default context menu is also displayed! I tried to prevent this by adding a preventDefault()
to the event in my listener, but this does not work:
function showContextMenu(e){
e.preventDefault();
// code to show custom context menu
}
$("#myId").click(500, showContextMenu);
Questions
- Can you prevent the iPad's default context menu to show?
- Can it by done using the jQuery Longclick plugin?
The Longclick plugin has some specific handling for the iPad (assuming by this snippet of it's source code):
if (!(/iphone|ipad|ipod/i).test(navigator.userAgent)){
$(this)
.bind(_mousedown_, schedule)
.bind([_mousemove_, _mouseup_, _mouseout_, _contextmenu_].join(' '), annul)
.bind(_click_, click)
}
So I assume this answers my second question (assuming the plugin used the correct event).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…