码迷,mamicode.com
首页 > 移动开发 > 详细

移动web端禁止长按a标签,弹出“在浏览器中打开”菜单

时间:2018-02-02 14:30:40      阅读:1957      评论:0      收藏:0      [点我收藏+]

标签:one   选中   prevent   star   jquery   click   弹出菜单   width   ima   

长按press事件会导致浏览器弹出菜单

技术分享图片

方法一:

苹果禁止:

-webkit-touch-callout: none;

 

安卓的不行。禁止弹出只能用js来控制:

$(‘a‘).ontouchstart = function(e) { 
    e.preventDefault(); 
};

 

方法二:

将<a>标签换成其他的标签,如<button>,<div>,<p>。然后绑定touchstart,click事件js跳转。

<div class="jump">链接</div>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
    $(.jump).on(touchstart, function () {
        location.href = "";
    })
</script>

 

如果想要禁止文本被选中,可以加上css

.jump {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

 

 

 

移动web端禁止长按a标签,弹出“在浏览器中打开”菜单

标签:one   选中   prevent   star   jquery   click   弹出菜单   width   ima   

原文地址:https://www.cnblogs.com/hcxwd/p/8404302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!