1.首先在h5中加入
<head> <style> .unselectable { -moz-user-select: none; -webkit-user-select: none; } </style> </head> <body> <div class="unselectable" unselectable="on"> The user is not able to select this text in Firefox, Google Chrome and Safari. In Internet Explorer and Opera, it is selectable only if the selection starts outside. </div> </body>
2.系统默认会有长按效果。
3.如果需要自定义效果
这个功能首先可以从两方面完成:
(1) 在js中完成:
处理android.selection.longTouch
(2) 安卓层处理:
首先使用OnTouchListener实现长按实现监听,然后实现WebView的Context menu,最后调用webview中的emulateShiftHeld(),为了适配安卓不同版本,最好使用反射方式调用.
开源项目参考:
这里推荐一个开源项目进行参考,: