Question web browser control: How to programatically access html code

skydiver

New member
Joined
Jun 21, 2006
Messages
3
Programming Experience
5-10
I'm using vb.net and the web browser control on a win form application where I have a dynamically created 'parent' html page that contains an 'iframe' that points to another dynamically created html page. Get it? Now, the exact reason why I'm doing this isn't the issue, but I'm trying to access the actual html code that resides within the child (iframe) page programatically through vb.net and the web browser control properties/methods (or whatever else...).

Here's what's going on with the code below:
The parent page gets 'navigated' to within the browser control that's sitting on my win form. The iframe gets loaded as well, and immediately begins the submission of the form data (currently 12 times, with an interval of 250ms). As each submission occurs, the parent gets updated through javascript with the current iteration number. When complete, the response to the form posting will present info within the iframe element. I need the actual HTML of the iframe element at this time but I'm not sure how to reference the child objects (elements?) within the web browser control. Can you help? Please include some examples if you're able. Thanks for the help! :D

Here's the Parent page:
VB.NET:
<HTML>
<BODY>
<form id="formsubmit">
<input type="text" id="postCounter" value="0";>
<iframe name="iFrame1" src="childpage.html" width="50%" align="left">
</form>
</iframe>
</BODY>
</HTML>

Here's the Child code:
VB.NET:
<HTML>
<head>
<SCRIPT type="text/javascript">
	var t=0;
	var i=0;
function load()
{
	t = setInterval("submitme()",250);
}

function submitme()
{
	var ctl;
	ctl=parent.document.forms[0].postCounter;
	i = parseInt(ctl.value);
	i=i+1;
	ctl.value = i;
	if (parseInt(i)<12)
	{
	  document.forms[0].submit();
	}
	else
	{
	  clearInterval(t);
	}
}
</SCRIPT>
</head>
<body onLoad="load();">
<form>  FORM TO POST GOES HERE</form>
</BODY>
</HTML>
 
To access the Html elements that the browser parses into the DOM tree you always use the Document property, this is your door in. In this case you must take a step back in the tree from the loaded document back to the Window object to access its Frames, then you select the correct frame by integer/string index and get into its Document tree. Here is a sample path that uses what I just described and display the body source of a frame:
VB.NET:
MsgBox(Me.WebBrowser1.Document.Window.Frames(0).Document.Body.InnerHtml)
 
Back
Top