简体   繁体   中英

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?

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');");
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM