• Welcome to Valhalla Legends Archive.
 

webbrowser control and user input information

Started by Tontow, June 17, 2005, 03:21 AM

Previous topic - Next topic

Tontow

I'm useing the webbrowser control. The web page has several textboxes cheackboxes and raido buttons. 

When the user hits send - Is it possable to detect what the user has entered into those textboxes cheackboxes and raido buttons?

The only way that I can think of right now is a key logger, but thats a bad thing to have in a program.

OnlyMeat

Quote from: Tontow on June 17, 2005, 03:21 AM
When the user hits send - Is it possable to detect what the user has entered into those textboxes cheackboxes and raido buttons?

The Webbrowser control has a IWebBrowser2 COM interface associated with it. That interface has a Document property, which when loaded with a html page is a pointer to the DOM(document object model) via the HTMLDocument coclass interface. This interface can be used to access elements within the page.

For further information refer to this link:-
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/iwebbrowser2.asp


Tontow


OnlyMeat

Quote from: Tontow on June 17, 2005, 01:08 PM
Isn't that a c/c++ reference?

It's an COM interface reference for the control. I'm assuming you can access those same properties through the normal IDispatch route as well.

Tontow

#4
I'm kind of flying blind with this one.........

  I found "Handling Events in Visual Basic Applications" - http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/iwebbrowser2.asp

So I'm guessing that the only way to do it is to write an event handler??  That seems like a bit much to me for grabbing user inputed information.

(edit: forgot the t on event)

OnlyMeat

#5
Quote from: Tontow on June 17, 2005, 05:58 PM
So I'm guessing that the only way to do it is to write an even handler??  That seems like a bit much to me for grabbing user inputed information.

From your original statement, you said you needed 2 things.
(1) To be informed when a user pushes a button on a html page.
(2) To then extract a set of data from some kind of input controls.

1. Requires you to be notified of events.
An example of this would be :-

Firstly setup a button/textbox html element tags on your page

<INPUT TYPE="BUTTON" name="MyPageButton">
<INPUT TYPE="TEXT" name="MyTextBox">


Then you implement the code to listen for events on it.

' Note this should be declared atleast at form scope
Dim WithEvents btnMyButton As HTMLButtonElement

' btnMyButton now contains a reference to the MyPageButton control
Set btnMyButton = wbCtrl.Document.all("MyPageButton")

' Sink the onclick event
Private Function btnMyButton _onclick() As Boolean
   
    ' You can then extract any data from the page here
    ' or execute a vbscript/jscript function in the page

End Function



2. Requires access to the DOM of the page so you can query the controls for their current values/state.


' Following on from the previous code example, you can now implement the functionality to access the DOM contents

' Sink the onclick event
Private Function btnMyButton _onclick() As Boolean
 
  dim txtMyTextBox as HTMLInputButtonElement
 
  ' Create a reference to the textbox page element
  set  txtMyTextBox = wbCtrl.Document.all("MyTextBox")

  ' Display the text boxes value string in a message box
  MsgBox txtMyTextBox .value

  '  You get the idea...

End Function


I haven't tested this code, it's just an approximation of what you need to do.