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

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

方法一:

苹果禁止:

-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;
}

 

 

 

相关文章:

  • 2022-12-23
  • 2021-08-26
  • 2021-11-25
  • 2022-12-24
  • 2021-10-26
  • 2021-08-09
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2021-09-12
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-01-28
相关资源
相似解决方案