如何接收Javascript返回的数组
this.webBrowser1.DocumentText = @" ";
object values = this.webBrowser1.Document.InvokeScript("GetValues", null);
foreach (object value in (IEnumerable)values)
{
MessageBox.Show(value.ToString());
}
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.parentWindow;
//读变量值
object o = win.GetType().InvokeMember ("var1", BindingFlags.GetProperty, null, win, new Object [] {});
//写变量值
win.GetType().InvokeMember ("var1", BindingFlags.SetProperty, null, win, new Object [] {"新的值"});
//调用方法
win.GetType().InvokeMember("testx",BindingFlags.InvokeMethod,null,win,new object[]{1});
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("kw").InnerText = "test";
doc.GetElementById("btn").InvokeMember("click");
项目中添加Micrsoft.mshtml引用
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript(
"function alert(str){if(str=='zswang')confirm(str);}", "javaScript");
}
HtmlElement btnSubmit = webBrowser.Document.All["submitbutton"];
HtmlElement tbUserid = webBrowser.Document.All["username"];
tmlElement tbPasswd = webBrowser.Document.All["password"];
if (tbUserid == null || tbPasswd == null || btnSubmit == null)
return;
tbUserid.SetAttribute("value", "smalldust");
tbPasswd.SetAttribute("value", "12345678");
btnSubmit.InvokeMember("click");