Link to home
Start Free TrialLog in
Avatar of JasonWilliam
JasonWilliam

asked on

Embedded internet explorer; create link and capture click?

Hey all.  I have an app in which I'm dynamically creating html webpages that essentially are custom reports based on database query results.  I'm displaying that html in an embedded IE window.

I'd like to add the functionality of having a user click a bit of information in their current report and that generates a new report.  Basically, I need to create a link, capture the click of that link and pass myself information about what exactly the user clicked.

This seems like it should be an easy thing to do, but I can't really find any examples.  Any thoughts?  Thanks!
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't understand what you mean by "embedded IE window".  Can you give me some idea what you mean by that?  It would help to determine if it is possible to achieve what you need.
Avatar of JasonWilliam
JasonWilliam

ASKER

Sure.  Thanks for trying to help.

I've written a VB.net form app that has a main form.  On that main form are several options and textboxes and buttons the user can check/configure/select/type etc.  Then they click 'Go'.  Based on all their input and configuration, I pull data down from many database tables, create an HTML stream with the data formatted in a very specific way, then send that stream to a System.Windows.Forms.WebBrowser window contained within my program's form.

What I'd like to do now is, as I'm creating that HTML stream, embedd "links" within it so that when displayed in the WebBrowser window, the user can click.  Once clicked, I want to capture that click, reshuffle the options that generated the original HTML, automatically click Go for them and generate a new HTML stream for display in the same WebBrowser.  In order to do that, I need some way of capturing the click event within the WebBrowser, and getting the info on the specific link they've clicked.

Does that make more sense?
Ok, so you are using a WebBrowser control, with custom HTML, and you need to add some behavior to anchor elements.  I am still in the dark about your reports, and how you need anchor elements to change to create new reports.  

"Information is king"
Ok I think I can boil it down really simply:  

Forget everything I'm doing.  Lets say I have a brand new windows form app, and all this app has is a WebBrowser window on it, that displays a clickable "Hello World" on it.  When the user clicks, how do I pop up a message box that says "Hello world!"

If you can get me that far, I can take it from there.
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok we're getting really close!  Here's where my lack of understanding comes in...

I'm going to write psudeocode representing what I want to do.  I understand this is not valid code; what I'm asking for is to have you show me how to make it valid code.  Make sense?

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           Dim docText As String
        docText = "<A HREF=""#TOC"" onClick=""(WebBrowserClicked("this will take you to the top!"))"">To the Table of Contents</A><p>"
        docText &= "<A HREF=""#TOC"" onClick=""(WebBrowserClicked("this will take you to the appendix!"))"">To the Appendix</A>"
        Me.WebBrowser1.DocumentText = docText

    End Sub

    Private Sub WebBrowserClicked(ByVal strWhatWasClicked As String)
        MsgBox(strWhatWasClicked)
    End Sub

End Class

Open in new window

You need to write JavaScript in the HTML, and that can't interact with your code.  You would need to use the alert function in JavaScript, or write your own function to perform something else.
So you're saying there's no way to have a click inside the WebBrowswer1 control fire an event my app can capture?  
I was trying to say that the only way that I know of, is to use JavaScript, but that doesn't mean that what you are looking for is impossible, I just don't know the specific answer.  You might be able to sub-class the WebBrowser, and get at the underlying COM interfaces, but that would only be a guess.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TLO pointed me in the right direction, and I was able to figure the rest out on my own.