Open baimindong opened 1 week ago
First click Button5, then click Button6.
private void Button5_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { string js = "function aaaa(){ alert('a'); }"; webview.ExecuteScript(js); //js = "aaaa();"; //webview.ExecuteScript(js); //// It well Done }
private void Button6_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { string js = "aaaa();"; webview.ExecuteScript(js); //// Not Execute , Nonresponse }
Thats perfectly normal as the code executes within a limited scope, which is valid only during the ExecuteScript. In order to do that you need to assign the function to the global (window) scope.
First click Button5, then click Button6.
private void Button5_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { string js = "function aaaa(){ alert('a'); }"; webview.ExecuteScript(js); //js = "aaaa();";
//webview.ExecuteScript(js); //// It well Done }
private void Button6_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { string js = "aaaa();"; webview.ExecuteScript(js); //// Not Execute , Nonresponse }