// Add an mshtml reference to the project
// Replace kernel functions
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using mshtml;
Namespace windowsapplication16
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void form1_load (Object sender, eventargs E)
{
Webbrowser1.navigate (@ "C: \ temp \ temp.htm ");
}
Private void webbrowserinclunavigated (Object sender, webbrowsernavigatedeventargs E)
{
Ihtmldocument2 vdocument = (ihtmldocument2) webbrowser1.document. domdocument;
Vdocument.parentwindow.exe cscript (
"Function alert (STR) {If (STR = 'zswang ') Confirm (STR );}","Javascript");
}
}
}
==========================================
How does one automatically call a button or <A> tag click event similar to the doc in the webbrowser control?
This. webbrowser1.document. Click + = new htmlelementeventhandler (document_click );
Void document_click (Object sender, htmlelementeventargs E)
{
If (readonly)
{
If (webbrowser1.document. activeelement. domelement is htmlanchorelement)
{
Htmlanchorelement em = (htmlanchorelement) webbrowser1.document. activeelement. domelement;
String href = em. href;
.......
}
}
}
Or:
Htmldocument hdoc = webbrowser. Document;
Htmlelement he object = hdoc. getelementbyid ("Object ID ");
He object. invokemember ("click ");
You can also use hdoc. getelementsbytagname ("tagname") to retrieve the object.
==========================================================
// C #2005 debugging successful
Private void webbrowserinclunavigated (Object sender, webbrowsernavigatedeventargs E)
{
Ihtmldocument2 vdocument = (ihtmldocument2) webbrowser1.document. domdocument;
Foreach (ihtmlelement velement in vdocument. All)
{
If (velement. tagname. toupper () = "frame ")
{
Ihtmlframebase2 vframebase2 = velement as ihtmlframebase2;
Vframebase2.contentwindow.exe cscript (
"Function alert (STR) {confirm ('[' + STR + ']');}", "JavaScript ");
}
}
}
========================================================== =
As a browser, how to obtain the specific link on the page and click it.
Actually relatively simple
Mshtml. ihtmldocument2 Doc = (mshtml. ihtmldocument2) This. axweb_browser.document;
Mshtml. ihtmlelementcollection myliks = Doc. links;
String tmp_ads_url = "xxxxxxx ";
Foreach (htmlanchorelementclass El in myliks)
{
If (El. href. tostring (). tolower () = tmp_ads_url)
{
El. Click ();
Break;
}
}
Okay. The problem that the current link does not open in a new window is also solved. The method is also very simple. You just need to find the specified link in my implementationCodeAdd
El.tar get = "_ Self ";
You don't have to say where to add it.