Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecuteScript Not Work #191

Open
baimindong opened this issue Nov 15, 2024 · 1 comment
Open

ExecuteScript Not Work #191

baimindong opened this issue Nov 15, 2024 · 1 comment

Comments

@baimindong
Copy link

baimindong commented Nov 15, 2024

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants