我尝试让事件点击 html 元素。使用我使用的 WebBrowser:
instance = Nothing
instance = WebBrowser1.Document
AddHandler instance.Click, AddressOf Document_Click
Run Code Online (Sandbox Code Playgroud)
但是对于 Webview2,我没有找到好的做法。我必须注入一个 javascript 代码吗?但是,我如何在 C# 或 Vb.net 应用程序中获取处理程序?
非常感谢。
这里有一个示例代码。我的函数中没有返回值:WebView1_WebMessageReceived。为什么 ?我想,我忘记了什么......
Imports System.IO
Imports Microsoft.Web.WebView2.Core
Imports Newtonsoft.Json
Class MainWindow
Public Sub New()
InitializeComponent()
InitializeSyncroComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
End Sub
Structure JsonObject
Public Key As String
'Public Value As PointF
End Structure
Async Sub InitializeSyncroComponent()
Await webview1.EnsureCoreWebView2Async
webview1.CoreWebView2.Navigate("https://google.fr/")
End Sub
Private Sub WebView1_WebMessageReceived(ByVal sender As Object, ByVal e As Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs)
Dim jsonObject …Run Code Online (Sandbox Code Playgroud)