我们知道通过oncontextmenu事件可以屏蔽浏览器右键菜单

$('img').on("contextmenu",function(E){E.preventDefault();E.stopPropagation();E.returnValue=false; return false;})

可是这一招在移动设备的浏览器中却失灵了,移动设备的浏览器的contextmenu是通过长按事件触发的,我想正是因为这和原因造成的上述手段失灵。

经调试发现,屏蔽touchstart事件可以解决:

 $('img').on("touchstart",function(E){E.preventDefault();E.stopPropagation();});

  但是,按下葫芦浮起瓢,上述代码屏蔽了系统邮件菜单的同时也造成longTap事件也不触发了,这直接导致自己的context menu也出不来了!没办法只能自己想办法解决了!以下代码基于app framework 实现了屏蔽手机浏览器的contextmenu、拖拽控件移动、并在长按时能够显示自己的contextmenu(af中的actionsheet):

var tapTimer=null;
$('img').on("touchstart",function(E){
E.preventDefault();E.stopPropagation(); var el=this;var me=$(this);$("#tip").text("in touchstart");
var t=E.touches[0];
tapTimer=setTimeout(function(){me.trigger('touchend').trigger('longTap');},1500); me.data("mx",t.pageX);me.data("my",t.pageY);
me.data("ex",el.offsetLeft);me.data("ey",el.offsetTop); })
.on('touchmove',function(E){E.preventDefault();E.stopPropagation();
if(tapTimer!=null)clearTimeout(tapTimer);
var t=E.touches[0];
var mx=parseInt(me.data("mx")),my=parseInt(me.data("my"));
var ex=parseInt(me.data("ex")),ey=parseInt(me.data("ey"));
var nx=ex+t.pageX - mx , ny=ey+t.pageY-my
$("#tip").text("in touch move : "+"or mx,my, new mx,my or ex,ey="+mx+","+my+","+t.pageX+","+t.pageY+","+ex+","+ey+" dest x,y="+nx+","+ny);
me.css({"left":nx+"px","top":ny+"px"}) ; })
.on('touchend',function(E){
if(tapTimer!=null)clearTimeout(tapTimer);
//E.preventDefault();E.stopPropagation();
}); $('img').on("contextmenu",function(E){E.preventDefault();E.stopPropagation();E.returnValue=false; return false;})
.on('longTap',function(E){E.stopPropagation();E.preventDefault()
$.ui.actionsheet(
[{
text: 'back',
cssClasses: 'red',
handler: function () {
alert("Clicked Back")
}
}, {
text: 'Alert Hi',
cssClasses: 'blue',
handler: function () {
alert("Hi");
}
}, {
text: 'Alert Goodbye',
cssClasses: '',
handler: function () {
alert("Goodbye");
}
}]
);
});

最新文章

  1. (转)socket Aio demo
  2. ios开发中的小技巧
  3. Python将MySQL表数据写入excel
  4. uGUI练习(六) ScrollView
  5. C++ map 映照容器
  6. Could not launch "app_name"
  7. MFC中,如何自定义用户消息
  8. HDU 1117 免费馅饼 二维动态规划
  9. hibernate批量删除和更新数据
  10. Linux 系统运行级别
  11. 《Programming WPF》翻译 第7章 3.笔刷和钢笔
  12. Button简单实例1
  13. jsp设置footer底部内容
  14. 【托业】【怪兽】TEST03
  15. VirtualBox中安装CentOS 7_Linux
  16. iOS中自动登录的设计
  17. Eclipse插件的安装(手动安装),以安装SVN插件和中文语言包为例
  18. [转]复制、移动和删除:cp, rm, mv
  19. 【C语言】练习3-5
  20. PyCharm导入tensorflow包报错的问题

热门文章

  1. 2. EM算法-原理详解
  2. Server.MapPath 出现未将对象引用设置到对象的实例
  3. jQuery Validate验证方法及教程
  4. Ubuntu 安装 vnc server
  5. Netty4.x中文教程系列(二) Hello World !<转>
  6. 网页QQ弹出
  7. sql 表连接基本的语法
  8. WebRTC 源码分析(五):安卓 P2P 连接过程和 DataChannel 使用
  9. R语言大小写字母转换
  10. Axiom3D:资源引用与加载基本流程.