WP7 InvokeScript错误 [英] WP7 InvokeScript error

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

问题描述

我有对WP7的方法 InvokeScript 一些困难:

I have some difficulties with the method InvokeScript on wp7:

webBrowser1.InvokeScript("eval", string.Format("document.getElementsByName('email').value='{0}'", _email));
webBrowser1.InvokeScript("eval", string.Format("document.getElementsByName('pass').value='{0}'", _pass));
webBrowser1.InvokeScript("eval", "document.forms[0].submit();");



不幸的是,当我尝试提交信息时,使用(document.forms [ 0] .submit()),将引发异常,与消息:

Unfortunately, when I try to submit information, using (document.forms[0].submit()), an exception is thrown with the message:

发生未知错误。错误:?80020101

An unknown error has occurred. Error: 80020101.

什么可问题是

推荐答案

首先确保IsScriptingEnabled是真实的,但我相信你做到了。

First make sure that IsScriptingEnabled is to true, but I assume you did it.

您的问题可能是,你得太快调用代码。似乎DOM是没有准备好操作时,导航的事件发生。例如:

Your problem is probably that you call the code too soon. It seems that the DOM is not ready for manipulation when the Navigated event occurs. Example:

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();

        Wb.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(Wb_Navigated);
        MouseLeftButtonDown += new MouseButtonEventHandler(MainPage_MouseLeftButtonDown);

        Wb.NavigateToString("<html><body><form action='http://google.com/'></form></body></html>");
    }

    void Wb_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        Wb.InvokeScript("eval", "document.forms[0].submit();"); // Throws 80020101
    }

    private void MainPage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        Wb.InvokeScript("eval", "document.forms[0].submit();"); // Works
    }
}

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

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