WP8.1 InvokeScript Error

孤街醉人 提交于 2019-12-23 19:13:15

问题


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?


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


来源:https://stackoverflow.com/questions/24611226/wp8-1-invokescript-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!