简体   繁体   English

WP8.1 InvokeScript错误

[英]WP8.1 InvokeScript Error

I am working on a Windows Phone 8.1 App. 我正在开发Windows Phone 8.1应用程序。 I have a problem with the InvokeScript method of the WebBrowser class. 我有一个WebBrowser类的InvokeScript方法的问题。 I have this in my XAML: 我在我的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: 我在使用InvokeScript的行上得到一个System.SystemException,它告诉我:

An unknown error has occurred. 出现未知错误。 Error: 80020006. 错误:80020006。

When I run the same code for Windows Phone 8 (not 8.1) I don't get the exception. 当我为Windows Phone 8(而不是8.1)运行相同的代码时,我没有得到异常。

Any ideas why I get an error with WP 8.1? 有什么想法我为什么会在WP 8.1中出错?

I found the solution here . 我在这里找到了解决方案。

The Loaded event is called too early. Loaded事件过早被调用。 I used the LoadCompleted event instead. 我使用了LoadCompleted事件。 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. 只要我导航到某些东西(我一直在放webBrowser.NavigateToString(“”); ),只有当WebBrowser控件已完全加载内容时才会调用LoadCompleted事件。

Here is the new code : 这是新代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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