2

Possible Duplicate:
Setting popup window to be a child of MDI Control when using WebBrowser Control

When I click a link < a onclick="OpenNewWindow(); /> in my WebBrowser control, I'd like to have the link open in a new WebBrowser .

I'm having two issues with this, however.

  1. How do I get the new URL
  2. How will the new browser window get the current Cookie?

    webBrowser1.NewWindow += (o, e) =>
    {
        e.Cancel = true;
        Form2 f = new Form2();
        f.URL = ""; // How to get the new url 
        f.Cookie = ""; // How to copy the cookie to the new webbrowser?
        f.ShowDialog();
    };
    
Community
  • 1
  • 1
shenhengbin
  • 4,236
  • 1
  • 24
  • 33

1 Answers1

1

You can inherit from WebBrowser and CancelEventArgs and customize the behavior completely. See this bug report and workaround from Microsoft: http://connect.microsoft.com/VisualStudio/feedback/details/115195/webbrowser-newwindow-event-does-not-give-the-url-of-the-new-window-in-eventargs

hoodaticus
  • 3,772
  • 1
  • 18
  • 28
  • Thanks for your advice... But if when I logging failed , This will always be exuted... – shenhengbin Jul 22 '11 at 02:41
  • I'm afraid I don't know what you mean. – hoodaticus Jul 22 '11 at 02:47
  • In my login method ....[webBrowser1.Document.All.GetElementsByName("form1:btn_login")[0].InvokeMember("click");] So , If the the check is false , it will always excute the navigate ? – shenhengbin Jul 22 '11 at 02:55
  • My bad - I wasn't paying enough attention to what you wanted. I've deleted the second part of my answer, and also, I think your code there is just fine. – hoodaticus Jul 22 '11 at 03:49