Touch API (e.g. touchstart) not working in MS Edge

心不动则不痛 提交于 2019-11-29 02:28:13

问题


my application is using the Touch API to detect touch events in JavaScript. Example:

$(".element").on("touchstart", function(event){
    alert("TRUE");
});

This works on any touch device with any browser like Android or iOS, however it doesn't work in MS Edge on a Windows 10 Tablet with or without conntected keyboard. The API seems to be supported: Compatibility list. However, I've tested: 'ontouchstart' in window and this returns false on this device. Furthermore mousedown seems to get fired.

What is going on here? What can I do to fire touch events on a Windows 10 tablet? I would like to keep the event only for touch devices. Switching to the Pointer Events API would include also Desktop devices and that is not what I want.


回答1:


for touch API, you have to activate a flag on Edge : in the address bar, enter about:flags and press enter. In the section Touch, you can enable touch events with the corresponding dropdown




回答2:


Did you enable custom touch handling ? You can do it with the following css snippet (on the body tag or just a container for geastures) :

-ms-touch-action: none;

Next, touch API is a webkit feature (maybe there is an error in CanIuse ?). IE and Edge have a similar feature known as Pointer API. But you can use a polyfill library like this : https://github.com/CamHenlin/TouchPolyfill




回答3:


Try using the pointerdown event. Some (much) more information. As you can see, touchstart is triggered by Edge but not in all configurations, when a keyboard is attached/paired for example, no touchstart.



来源:https://stackoverflow.com/questions/33300962/touch-api-e-g-touchstart-not-working-in-ms-edge

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