Webbrowser control - opening link in new window
-
Hi Coders I am using a webbrowser control in my winform application. I want to open all the links in the same window even though if the link is having the target=_blank property also. Its very urget. Please help me out. Oohmesh
You need to add event handlers to handle "NewWindow" event when the user clicks on a link with the target not on the current webbrowser 1. For Pre Windows XP SP2
axWebBrowser.NewWindow2
2. For Windows XP2 and later there is another event namedaxWebBrowser.NewWindow3
The whole code for this would lookaxWebBrowser.NewWindow2 += new AxSHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(axWebBrowser_NewWindow2); try { axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3); } catch ( Exception ) { // Not XP SP2 - just ignore }
Now in the event handlers all you have to do is block the new window from opening by puttinge.Cancel = true;
and redirect the current webbrowser to the new URL sent by the event. See more at NewWindow3[^] Jup -
You need to add event handlers to handle "NewWindow" event when the user clicks on a link with the target not on the current webbrowser 1. For Pre Windows XP SP2
axWebBrowser.NewWindow2
2. For Windows XP2 and later there is another event namedaxWebBrowser.NewWindow3
The whole code for this would lookaxWebBrowser.NewWindow2 += new AxSHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(axWebBrowser_NewWindow2); try { axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3); } catch ( Exception ) { // Not XP SP2 - just ignore }
Now in the event handlers all you have to do is block the new window from opening by puttinge.Cancel = true;
and redirect the current webbrowser to the new URL sent by the event. See more at NewWindow3[^] Jup -
Where i ll find this "axWebBrowser" class...Pls send the namespace. Aur it's an coponent u r using...:) Anuj
That's the variable name. The activeX browser could be found on your system. With .NET 1.1 the simplest way is that you should import that COM component from system32/shdocvw.dll. .NET 2.0 already have a web browser control for you by default from the toolbox. -Good Luck Jup