I have a c# web browser and one of the pages it displays has a form. When the form is submitted it posts data to a new window in IE. I want to catch that data and forward it to another C# web browser that I have in my application. So I don't want it to open an IE browser when the javascript function window.open is called, I want it to open it in the 2nd browser window.
views:
705answers:
3Redirect WinForms web browser Control pop ups to another WinForms web browser control with form data
You cannot do it directly with WebBrowser because it does not give you the url into the eventargs of the NewWindow event, but there's a solution here by inheriting the WebBrowser control and adding a new event that will give you the url. Then you just have to cancel the navigation (with the Cancel property of the event) and point to the new url into your other browser.
Edit
Ok, then you will have to do much manual work by first disallowing a new window and then getting the submit event of the form like this:
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Forms[0].AttachEventHandler("onsubmit",
new EventHandler(submit));
}
private void submit(object o, EventArgs e) {...}
And do all the handling into the submit method, but you will have to look into the document elements to extract all the post values and post them manually into your other webbrowser control.
You may also have to modify the html code of the onSubmit attribute of the form to not open a new window because it won't be easy to stop it opening.
Note the change I made in the subject. There's no such thing as a "C# web browser".
You are using the Windows Forms Web Browser Control in a C# program. You want to be notified when a new windows is being created so that you can create another Windows Forms form to display another Web Browser Control containing the new content.
I found this post helpful when dealing with a similar issue: CodeProject - MultiTab Browser