如何在WebView2中让'ontounchend in document'返回true

问题描述 投票:0回答:1

在WebView2浏览器中,我想用手指移动东西。 但不支持ontouchxxx(ontouchstart,ontouchend)。 换句话说,文档中的“ontouchend”返回 false。

我尝试了以下各种方法,但没有成功。

webView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
  1. 设置触摸模拟启用
    await webView2.EnsureCoreWebView2Async(null);
    if (webView2.CoreWebView2 != null)
    {
        webView2.CoreWebView2.CallDevToolsProtocolMethodAsync("Emulation.setEmitTouchEventsForMouse", "{'enabled': true }");
    }
  1. --enable-features=msWebView2EnableDraggableRegions
    string arg = @"--enable-features=""msWebView2EnableDraggableRegions""";
    var opts = new CoreWebView2EnvironmentOptions { AdditionalBrowserArguments = arg };
    var webView2Environment = await CoreWebView2Environment.CreateAsync(null, null, opts);
    await webView21.EnsureCoreWebView2Async(webView2Environment);
  1. 是否已启用滑动导航
    await webView2.EnsureCoreWebView2Async(null);
    if (webView2.CoreWebView2 != null)
    {
        webView2.CoreWebView2.Settings.IsSwipeNavigationEnabled = true;
    }
  1. 更改 UserAgent,如 chrome、edge 的 iPad 模拟器,在文档中为“ontouchend”返回 true
     await webView2.EnsureCoreWebView2Async(null);
     if (webView2.CoreWebView2 != null)
     {
         webView2.CoreWebView2.Settings.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15";
     }
microsoft-edge touch-event webview2
1个回答
0
投票

在我看来,这是设计使然,因为这个API只适用于触摸设备,如果你想在电脑浏览器上实现这样的功能,我想你可能需要使用其他一些插件。

© www.soinside.com 2019 - 2024. All rights reserved.