WP8.1 InvokeScript错误 [英] WP8.1 InvokeScript Error

查看:340
本文介绍了WP8.1 InvokeScript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Windows Phone 8.1应用程式。我有一个WebBrowser类的InvokeScript方法的问题。
我在XAML中有这个:



当我运行这个代码时:

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

我得到一个System.SystemException在InvokeScript行,告诉我这:


发生未知错误。错误:80020006。


当我对Windows Phone 8(不是8.1)运行相同的代码时,我没有得到异常。 / p>

任何想法为什么我得到WP 8.1的错误?

解决方案

我在此处找到了解决方案。



Loaded事件过早调用。我使用LoadCompleted事件。只要我导航到某个东西(我一直在放置 webBrowser.NavigateToString(); )LoadCompleted事件将只有当WebBrowser控件完全加载内容时才会被调用。



这是新的代码:

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


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

这篇关于WP8.1 InvokeScript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆