移動web端禁止長按a標籤,彈出「在瀏覽器中打開」菜單

長按press事件會致使瀏覽器彈出菜單css

方法一:html

蘋果禁止:jquery

-webkit-touch-callout: none;

 

安卓的不行。禁止彈出只能用js來控制:web

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

 

方法二:瀏覽器

將<a>標籤換成其餘的標籤,如<button>,<div>,<p>。而後綁定touchstart,click事件js跳轉。
spa

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

 

若是想要禁止文本被選中,能夠加上csscode

.jump {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
相關文章
相關標籤/搜索