WebBrowser 控件的调用脚本总是给我错误。此 html 脚本从http://validator.w3.org进行验证。我编写了这样的代码,以便在单击“button1”时 webBrowser1 调用函数“setCredentials”。我不知道为什么这会给出一个错误
“发生未知错误。错误:80020006。”
public TestInvokeScript()
{
InitializeComponent();
LoadHtml();
webBrowser1.IsScriptEnabled = true;
webBrowser1.NavigateToString(_html);
button1.Content = "Set Credentials";
}
private void LoadHtml()
{
_html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" +
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" +
"<head>" + "<meta name=\"generator\" content=\"HTML Tidy for Linux (vers 6 November 2007), see www.w3.org\" />" +
"<script type=\"text/javascript\">" +
"//<![CDATA[" +
" function setCredentials()" +
" {" +
" document.getElementById(\"email\").value = \"test@gmail.com\";" +
" }" +
"//]]>" +
"</script>" +
"<title></title>" +
"</head>" +
"<body>" +
"<form action=\"https://cloudmagic.com/k/login/send\" method=\"post\">" +
"<input id=\"email\" type=\"text\" value=\"\" /> " +
"<input id=\"password\" type=\"password\" />" +
" <button type=\"submit\" id=\"login_send\">Login</button>" +
" </form>" +
"</body>" +
"</html>";
}
private void button1_Click(object sender, RoutedEventArgs e)
{
var obj = webBrowser1.InvokeScript("setCredentials");
}
我在做什么错。?