我在Windows Form中用axWebBrowser控件来操作网页,
在获取用户点击按钮事件,已经成功,
但是同时又出现了新的问题,
如果那个按钮原来用单击事件:
<input type="button" class="b_foot" value="订单提交" id="nextBtn" onclick="doCommit()"/>我在程序中使用代码:
onclickHandler = new BrowserEventHandler();
onclickHandler.Fire = new ElementEventFire(OnClickButton);
photo.onclick = onclickHandler;
来获取用户单击事件,这个单击事件获取到了,但是网页中原来的
onclick="doCommit()"事件却没有了反应,
我如何在获取点击事件,而又不影响原本页面中的动作那。
请高手赐教。
在获取用户点击按钮事件,已经成功,
但是同时又出现了新的问题,
如果那个按钮原来用单击事件:
<input type="button" class="b_foot" value="订单提交" id="nextBtn" onclick="doCommit()"/>我在程序中使用代码:
onclickHandler = new BrowserEventHandler();
onclickHandler.Fire = new ElementEventFire(OnClickButton);
photo.onclick = onclickHandler;
来获取用户单击事件,这个单击事件获取到了,但是网页中原来的
onclick="doCommit()"事件却没有了反应,
我如何在获取点击事件,而又不影响原本页面中的动作那。
请高手赐教。
解决方案 »
- 请教关于GridView中加入DropDownList的问题?
- if (null == oraConnection)与 if (oraConnection==null)有什么区别
- 想做一个只接受数字且能按位调整大小的textbox控件
- 正则表达式匹配
- PropertyGrid ComboBox
- 这个字符该怎么分割?
- 应用程序加载dl中的窗体,并将该窗体放在主程序的panel中(有挑战性,高手请进)
- dataRow 转换成dataTable
- GDI+绘图相关问题
- 那里有免费的动态域名解析软件,可以运态解析我的ADSL的公网IP,然后用域名登陆我的个人服务器网页呢?
- 如何webbrowser 禁止脚本运行
- 未处理 System.IndexOutOfRangeException
//这样处理,先找到按钮对象
HtmlElement btnTarget= webBrowser1.Document.GetElementById("btnTarget"); if (btnTarget== null )
{
return;
}
btnTarget.InvokeMember("click");
if (bt != null)
{
backgroundWorker1.RunWorkerAsync("submit");
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
HtmlElement btn= this.webBrowser1.Document.GetElementById("submit");
btn.InvokeMember("click");
}
webBrowser1.Document.GetElementById("").InvokeMember("Click");
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
function fun1(){
var aa = document.getElementById("aaa");
aa.innerHTML = "---";
aa.onclick = function(){fun2();}
}
function fun2(){
var aa = document.getElementById("aaa");
aa.innerHTML = "+++";
aa.onclick = function(){fun1();}
} </script>
</HEAD> <BODY>
<table width="100%" border="0" cellspacing="2">
<tr>
<td width="100%" height="25" bgcolor="#33BB33">
<P>
<a id="aaa" style="cursor:hand" onClick="fun1()">+++</a>
</P>
</td>
</tr>
</table> </BODY>
</HTML>
你的意思找不到代表按钮的HtmlElement ?
你有代码吗?一楼的代码也是按你以前的代码改的。
你有代码吗?一楼的代码也是按你以前的代码改的。
你用WebBrowser吧!
window.open(' dmain.htm','CRM','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500,left=0,top=0');
window.opener=null;
window.open("","_self");
window.close();
时无效,现在我只在axWebBrowser 解决了那个问题
可能我说的不太明白,让大家有些误解:
我程序用的axWebBrowser控件,用IHTMLDocument2获取多层iframe里的代码。
mshtml.IHTMLDocument2 idc = frm.document;
在IHTMLDocument2好像没有InvokeMember这个,并且我要的不是自动触发事件,而是当用户点击一个按钮时获得他点击的动作,就是说我要知道他点了比如提交按钮,这样我可以在程序中加一些操作,但是那个提交按钮原本有onclick事件,我程序在扑捉他点击动作的同时不能影响按钮原本的onclick事件。
调用方法参考InvokeMember的源代码
这个问题好解决呀!
WebBrowser 控件应用:弹出新窗体和关闭窗口
因为新页面里有类似这样的验证。<script language="javascript">
if(typeof(opener) == "undefined")
{
alert("禁止非法进入页面!");
window.opener=null;
window.open("","_self");
window.close();
}
</script>因为我要处理的页面比较复扎,是移动公司的一个业务系统,对浏览器做了很多的限制。下面是我处理页面的一部分代码,请看指教一下如何修改能解决问题:
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
if (axWebBrowser1.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
mshtml.IHTMLWindow2 frm = (mshtml.IHTMLWindow2)doc.parentWindow;
mshtml.FramesCollection frms = frm.frames;
object x;
for (int i = 0; i < frms.length; i++)
{
x = i;
mshtml.IHTMLWindow2 ifrme = (mshtml.IHTMLWindow2)frms.item(ref x);
if (ifrme != null) { getiframe(ifrme); }
}
}
}private void getiframe(mshtml.IHTMLWindow2 frm)
{
mshtml.IHTMLDocument2 idc = frm.document;
mshtml.IHTMLElementCollection hec = ((mshtml.IHTMLDocument3)idc).getElementsByTagName("input");
mshtml.DispHTMLInputElement photo = null;
foreach (object obj2 in hec)
{
photo = obj2 as mshtml.DispHTMLInputElement;
if (photo.id == "btnSave" && photo.value == "交费")
{
onclickHandler = new BrowserEventHandler();
onclickHandler.Fire = new ElementEventFire(OnClickButton);
photo.onclick = onclickHandler;
}
} mshtml.IHTMLWindow2 idc_parentwindow = (mshtml.IHTMLWindow2)idc.parentWindow;
mshtml.FramesCollection myfrm = idc_parentwindow.frames;
int idc_parentwindow_count = myfrm.length;
if (idc_parentwindow_count > 0)
{
object x;
for (int i = 0; i < idc_parentwindow_count; i++)
{
x = i;
mshtml.IHTMLWindow2 ifm = (mshtml.IHTMLWindow2)myfrm.item(ref x);
if (ifm != null) { getiframe(ifm); }
}
}
}
{
if (link.InnerText != null && link.InnerText.Contains("下一页"))
{
usefullink = link;
break;
}
}
应该这样! private void button1_Click(object sender, EventArgs e)
{
HtmlElement btnSearch = webBrowser1.Document.GetElementById("btnG");
HtmlElement txtContact = webBrowser1.Document.GetElementById("q");
if (txtContact == null || btnSearch == null)
{
return;
}
txtContact.SetAttribute("value", "中学");
btnSearch.InvokeMember("click"); HtmlElementCollection links = this.webBrowser1.Document.Links;
bool a = GoTargetPage(links);
//如果没有找到,就去下一页找
if (a == false)
{
foreach (HtmlElement link in links)
{
if (link.InnerText == "下一页")
{
link.InvokeMember("click");
}
}
}
}