gpt4 book ai didi

c# - WP7 InvokeScript 错误

转载 作者:行者123 更新时间:2023-11-29 20:10:58 24 4
gpt4 key购买 nike

我在 wp7 上使用 InvokeScript 方法时遇到了一些困难:

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()) 提交信息时,异常被抛出并显示消息:

An unknown error has occurred. Error: 80020101.

可能是什么问题?

最佳答案

首先确保 IsScriptingEnabled 为 true,但我假设您做到了。

您的问题可能是您过早地调用了代码。当 Navigated 事件发生时,DOM 似乎还没有准备好进行操作。示例:

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
}
}

关于c# - WP7 InvokeScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9911985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com