最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent text selection on tap and hold on iOS 13Mobile Safari - Stack Overflow

programmeradmin1浏览0评论

Tapping and holding on a DIV causes Safari to select (i.e. highlight) the surrounding text and the phone to vibrate, even if this DIV has a user-select property set to none. This is very annoying in the context of my app. It seems to be specific to iOS 13 and its Haptic Touch.

I tried to e.preventDefault() on the touchstart event and it worked, but at the same time disabled scrolling capabilities.

I also tried to e.preventDefault() on the webkitmouseforcewillbegin event, as remended in the Apple documentation, but this didn't work at all.

Anyone knows how to fix this?

Video:

Tapping and holding on a DIV causes Safari to select (i.e. highlight) the surrounding text and the phone to vibrate, even if this DIV has a user-select property set to none. This is very annoying in the context of my app. It seems to be specific to iOS 13 and its Haptic Touch.

I tried to e.preventDefault() on the touchstart event and it worked, but at the same time disabled scrolling capabilities.

I also tried to e.preventDefault() on the webkitmouseforcewillbegin event, as remended in the Apple documentation, but this didn't work at all.

Anyone knows how to fix this?

Video: https://youtu.be/SstDm0M8RN0

Share Improve this question asked May 17, 2020 at 16:21 tavoynetavoyne 6,5692 gold badges16 silver badges26 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Calling event.returnValue = false; from all touch events (touchstart, touchend, touchmove, touchcancel) prevents from the surrounding text selection. Here is fiddle: https://jsfiddle/j_u_l_e_e/yLdt1s4o/

发布评论

评论列表(0)

  1. 暂无评论