How to completely remove mobile browser long-press vibration?

为君一笑 提交于 2020-05-11 06:17:28

问题


I'm trying to completely remove the vibration that occurs on a long press of an element in a mobile browser.

Specifically, I have an image that I'm adding my own long-press functionality to, but the subtle short-vibrate that happens by default is interfering and I need to disable it.

I've successfully stopped the usual context menu from appearing by overriding it as follows:

window.oncontextmenu = function (event) {
  event.preventDefault();
  event.stopPropagation();
  return false;
};

I've also added CSS to stop highlights and text selection etc - but I haven't been able to figure out what's causing the default vibrate after a few hundred ms.

Is there another lifecycle event that's popped on a long-press in a mobile browser, in or around oncontextmenu?

Full plunker Example here, long-press on the image from a mobile browser (I'm using chrome on Android) to see what I mean: https://plnkr.co/edit/y1KVPltTzEhQeMWGMa1F?p=preview


回答1:


I have been going through the same issue for the last day or so with my own React App, I have gone through the same steps as you with no success. Currently I have an Android app that is opening up the React web app using webView, what I have found is:

I am fairly sure what you(we)'re trying to do can't be done purely though ReactJS alone, the solution I used, as I am loading my ReactJS app through an Android app was to add the method:

android:hapticFeedbackEnabled="false"

to my AndroidManifest.xml file (docs here: https://developer.android.com/reference/android/view/View#attr_android:hapticFeedbackEnabled)

If you want to read more into native Android solutions there is a section of the Android Cookbook that focuses on custom haptic feedback: http://androidcookbook.com/Recipe.seam?recipeId=1242

Alternatively, there are solutions available through React-Native. React Native has a built in Vibration Module, config docs available here: https://facebook.github.io/react-native/docs/vibration



来源:https://stackoverflow.com/questions/46087752/how-to-completely-remove-mobile-browser-long-press-vibration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!