prompteus
prompteus

Reputation: 1032

Xamarin form webview Eval not calling javascript

I use following code to load page to MyWebView:

private void DisplayLocalPage(string filename)
{
    var html = new HtmlWebViewSource();
    html.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
    html.Html = ReadFile(filename);
    MyWebView.Source = html;
    MyWebView.Eval("alert(200)");
}

Page is rendered well - all scripts run too, but this alert isn't fired, what are possible reasons?

Upvotes: 2

Views: 3755

Answers (2)

Kamil Smrčka
Kamil Smrčka

Reputation: 81

Please try this:

webView.Navigated += (o, s) => {
     webView.Eval("alert('text')");
     };

Upvotes: 3

prompteus
prompteus

Reputation: 1032

I think I figured out why it might not work. The Eval is triggered before the WebView is fully initialized or web page is rendered, so the script is trigerred, but doesn't have any effect.

Upvotes: 0

Related Questions