Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP8.1 InvokeScript Error

I am working on a Windows Phone 8.1 App. I have a problem with the InvokeScript method of the WebBrowser class. I have this in my XAML:

And when I run this code:

myWebBrowser.Loaded += (object sender, RoutedEventArgs e) =>
{
    webBrowser.IsScriptEnabled = true;
    webBrowser.InvokeScript("eval", "alert('foo')");
};

I get a System.SystemException on the line with InvokeScript that tells me this:

An unknown error has occurred. Error: 80020006.

When I run the same code for Windows Phone 8 (not 8.1) I don't get the exception.

Any ideas why I get an error with WP 8.1?

like image 211
alexandre-tsu-manuel Avatar asked Feb 07 '26 16:02

alexandre-tsu-manuel


1 Answers

I found the solution here.

The Loaded event is called too early. I used the LoadCompleted event instead. As long as I navigate to something (I've been putting webBrowser.NavigateToString(""); ) the LoadCompleted event will be called only when the WebBrowser control has fully loaded content.

Here is the new code :

webBrowser.LoadCompleted += (object sender, NavigationEventArgs e) =>
{
    webBrowser.IsScriptEnabled = true;
    webBrowser.InvokeScript("eval", "alert('foo');");
};
like image 137
alexandre-tsu-manuel Avatar answered Feb 09 '26 07:02

alexandre-tsu-manuel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!