MikeThelwall
asked on
Web browser control and form field clicking
Is there any way with the web browser control to respond to the user clicking on a form field in a web page? Ideally I would like to write some code so that when a form field is clicked on, the form field is sent to a procedure as an HTMLAnchorElement object.
If there is not a direct way, I would be happy with some kind of polling routine searching for which field has the focus.
I can't use a DHTML solution because it has to work for thousands of other people's web pages.
If there is not a direct way, I would be happy with some kind of polling routine searching for which field has the focus.
I can't use a DHTML solution because it has to work for thousands of other people's web pages.
ASKER
Thanks a lot, that sounds perfect, a really clever solution. Please post the code.
I had given up on being able to solve this problem and thought that it was impossible.
I had given up on being able to solve this problem and thought that it was impossible.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant - and thanks for the extra explanation too. I can finish my project now at last.
I just looked through the code again. There is a line in there that changes the background color to a random number.
g_oDocBody.bgColor = Int((32000 * Rnd) + 1)
This was left over from some monkeying around I was doing. Obviously, you don't need it, but I'm sure you already figured that out.
g_oDocBody.bgColor = Int((32000 * Rnd) + 1)
This was left over from some monkeying around I was doing. Obviously, you don't need it, but I'm sure you already figured that out.
ASKER
Problems - the code is excellent and works fine on links but does not seem to transfer to form fields. I've tried it with various form element and VB is happy to assign the withevents object to a form field but does not seem to recognise the click event - I get the javascript click event on the page instead. I've tried the focus event too. I'm guessing that VB does not yet have the functionality to deal properly with form fields(?) - if so, I'll have to wait for it, I guess. I'm still happy with the code though - it is obviously the 'correct' way to do it.
Have you tried removing the javascript click event? Perhaps only one handler is allowed and the javascript one takes precedence. I may have some time today to fool around with this...I'll see what I can do, but don't get your hopes up.
I don't know where you are in the world, but if you celebrate Thanksgiving...have a good one.
Mark
I don't know where you are in the world, but if you celebrate Thanksgiving...have a good one.
Mark
ASKER
I've tried loads of things now and given up - guess that you didn't have any more luck?
I've written the codee that should work and will wait until Microsoft catch up!!! In the meantime I am using a workaround.
Thanks again for the help. I'm in the UK where we only hear about Thanksgiving on the Simpsons - but I was in Houston ten years ago and remember the Pumpkin pie!
I've written the codee that should work and will wait until Microsoft catch up!!! In the meantime I am using a workaround.
Thanks again for the help. I'm in the UK where we only hear about Thanksgiving on the Simpsons - but I was in Houston ten years ago and remember the Pumpkin pie!
I had some code lieing around from answering a previous question so I modified it a little bit and came up with the following. My app is a VB 5 application that uses the Microsoft Web Browser control.
1. I navigate the browser control to a particular URL in response to a button click.
2. When the DocumentComplete event is fired from the control to my VB app (I set up the WithEvents stuff previously), I then iterate through the body of the document and look for a particular Anchor Element (in my case, the first anchor that has "html" in its href attribute).
3. I had previously declared (dimmed with events) a global variable of type HTMLAnchorElement. At this point, I assign the element found in step 2 to this variable.
4. I had previously added a handler for the onclick event of the global variable referred to in step 3 and added a msgbox statement to it to see if it would be called.
Lo and behold, when I clicked on that link, my handler was called and the browser's handler WAS NOT called. When I clicked on other anchor elements, my handler was not called.
This isn't the exact fulfillment your question, so I'll only post the code if you really want to see it. Perhaps it will spark some other thought in your brain that will answer your question. Let me know if you want the code.
The challenge for you will be to handle the onclick event for *every* anchor element in the body of the document.