javascript 如何确保在 Firefox 桌面浏览器中启用触摸事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25024197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:46:18  来源:igfitidea点击:

How to make sure touch events are enabled in Firefox desktop browser?

javascriptfirefoxwindows-7touch

提问by William Smith

I used a simple test on a windows 7 desktop with touch capabilities. For simplicity it was something like this:

我在具有触摸功能的 Windows 7 桌面上使用了一个简单的测试。为简单起见,它是这样的:

temp_div.addEventListener('touchstart', function(e){ /*confirm */ }, false)
temp_div.addEventListener('pointerdown', function(e){ /*confirm */ }, false)
temp_div.addEventListener('mousedown', function(e){ /*confirm */ }, false)

In chrome, the 'touchstart' was confirmed. In IE, the 'pointerdown' was confirmed. In Firefox, the 'mousedown' was confirmed.

在 chrome 中,'touchstart' 被确认。在 IE 中,'pointerdown' 被确认。在 Firefox 中,“鼠标按下”被确认。

After troubleshooting, I ultimately had to go to 'about:config' in Firefox and change the 'dom.w3c_touch_events.enabled' value from 0 to 1. This caused the 'touchstart' to be confirmed in Firefox.

排除故障后,我最终不得不转到 Firefox 中的“about:config”并将“dom.w3c_touch_events.enabled”值从 0 更改为 1。这导致 Firefox 中的“touchstart”得到确认。

My questions are these:

我的问题是这些:

Shouldn't this have already been enabled on a touch-capable machine? IE and Chrome were configured properly and Firefox was not. (This was a brand new download of Firefox 31).

这不应该已经在具有触摸功能的机器上启用了吗?IE 和 Chrome 已正确配置,而 Firefox 未正确配置。(这是 Firefox 31 的全新下载)。

Is there anyway to enable touch events remotely in a case like this so that Firefox behaves similarly to the other browsers?

无论如何,在这种情况下是否可以远程启用触摸事件,以便 Firefox 的行为与其他浏览器相似?

Thanks

谢谢

回答by William Smith

In order to enable touch events in the desktop version of Firefox, type "about:config" into the address bar of the browser, click the "I'll be careful, I promise!" button and scroll down until you find "dom.w3c_touch_events.enabled" ....when you click this item, a dialog box will appear that allows you to change the value of the setting.

为了在桌面版 Firefox 中启用触摸事件,在浏览器的地址栏中输入“about:config”,点击“我会小心,我保证!” 按钮并向下滚动,直到找到“dom.w3c_touch_events.enabled”....当您单击此项时,将出现一个对话框,允许您更改设置的值。

disable=(0) enable=(1) auto-detect=(2)

禁用=(0)启用=(1)自动检测=(2)

This should be set to "auto-detect" by default, but currently, the desktop version of Firefox is set to "disable" due to some bugginess.

这应该默认设置为“自动检测”,但目前,由于某些错误,桌面版 Firefox 设置为“禁用”。

Info about this setting can be found here: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Touch_events

可以在此处找到有关此设置的信息:https: //developer.mozilla.org/en-US/docs/Web/Guide/Events/Touch_events

excerpt:

摘抄:

The dom.w3c_touch_events.enabled tri-state preference can be used to disable (0), enable(1), and auto-detect(2) support for standard touch events; by default, they're on auto-detect(2). After changing the preference, you must restart the browser for the changes to take effect.

dom.w3c_touch_events.enabled 三态首选项可用于禁用 (0)、启用 (1) 和自动检测 (2) 对标准触摸事件的支持;默认情况下,它们处于自动检测(2)状态。更改首选项后,您必须重新启动浏览器才能使更改生效。

Note: As of Gecko 24.0, the touch events support introduced with Gecko 18.0 has been disabled on the desktop version of Firefox, as some popular sites including Google and Twitter are not working properly. Once the bug is fixed, the API will be enabled again.
The mobile versions including Firefox for Android and Firefox OS are not affected by this change. Also, the API has been enabled on the Metro-style version of Firefox for Windows 8.

注意:从 Gecko 24.0 开始,Gecko 18.0 引入的触摸事件支持已在桌面版 Firefox 上禁用,因为包括 Google 和 Twitter 在内的一些流行网站无法正常工作。修复错误后,将再次启用 API。
包括 Firefox for Android 和 Firefox OS 在内的移动版本不受此更改的影响。此外,该 API 已在适用于 Windows 8 的 Metro 风格版本的 Firefox 上启用。

回答by Ralph Ritoch

Touch events are not working in Firefox currently (version 48.0.1) but it is possible to enable pointer events by browsing to about:configand setting dom.w3c_pointer_events.enabledto true. The event object passed to your handler will contain a pointerType property with the value of "touch" if it was a touch event.

触摸事件当前在 Firefox(版本 48.0.1)中不起作用,但可以通过浏览about:config并将dom.w3c_pointer_events.enabled设置为true来启用指针事件。传递给处理程序的事件对象将包含一个指针类型属性,如果它是一个触摸事件,它的值为“touch”。

See: https://mobiforge.com/design-development/html5-pointer-events-api-combining-touch-mouse-and-pen

请参阅:https: //mobiforge.com/design-development/html5-pointer-events-api-combining-touch-mouse-and-pen

回答by Ryan

There is a dom.w3c_touch_events.legacy_apis.enabledevents configuration option in Firefox 72. It is off by default. Turning it on helps some websites with touch-based drag and drop. Atlassian Jira in particular.

dom.w3c_touch_events.legacy_apis.enabledFirefox 72 中有一个事件配置选项。默认情况下它是关闭的。打开它可以帮助一些网站使用基于触摸的拖放。特别是 Atlassian Jira。