When using the .NET WebBrowser control how do you open a link in a new window using the the same session (ie.. do not start a new ASP.NET session on the server), or how do y
Slightly cleaned up version of Greg's answer. It modifies the passed-in control's behavior rather than relying on a global variable. Usage:
InlinePopups(webBrowser1);
Code:
// interface to expose ActiveX methods
private SHDocVw.WebBrowser_V1 Web_V1;
private void InlinePopups(WebBrowser browser)
{
// hooks to force new windows to open in the current instance
Web_V1 = (SHDocVw.WebBrowser_V1)browser.ActiveXInstance;
Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler((string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) =>
{
Processed = true; // stop event from being processed
// open in the existing window
browser.Navigate(URL);
});
}
Still needs the reference to %WINDIR%\system32\shdocvw.dll, of course.