OutSystems / CefGlue

.NET binding for The Chromium Embedded Framework (CEF)
MIT License
277 stars 41 forks source link

ExecuteScript Not Work #191

Open baimindong opened 1 week ago

baimindong commented 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 }

joaompneves commented 1 week ago

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.