C# webbrowser control and links

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • canadamaple
    New Member
    • Oct 2008
    • 1

    C# webbrowser control and links

    Hi i have been trying to find a way to the url when a user clicks on a link. now let me be clear I am aware of the status text option. I am looking for away to capture the links that do not show a status text option. It is those one that the typical status text option does not work. With the code i have I have capture any links in webpages but i have discovered there are moments when people don't use links but rather use javascript to make links on the fly and therefore this doesn't work.

    Code:
            private void LinkClicked(object sender, EventArgs e)
            {
    
            HtmlElement link =webBrowser1.Document.ActiveElement;
            url = link.GetAttribute("href");
            }
    
            private void webBrowser1_Navigating(object sender,
                  WebBrowserNavigatingEventArgs e)
                {
                           // the URL that it is going to..
                      MessageBox.Show(webBrowser1.StatusText.ToString()) ;
    
                               // you can just let the browser handle this since it can justnavigate within its current frame... but you could handle it here too
    
                         // tell system we want to handle this event ourselves
                          // e.Cancel = true;
                           } // end webBrowser1_Navigating ()
    
            private void webBrowser1_NewWindow(Object sender, CancelEventArgs e)
            {
                {
                    e.Cancel = true;
                    webBrowser1.Navigate(url);
                    //webBrowser1.Navigate((), false);
                    e.Cancel = true;
                } 
           }
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    Your code looks pretty similar to this example's. If it isn't the same, well try working with that code and seeing if its any different.

    joedeene

    Comment

    Working...