我在 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/