打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c#

   

This question already has an answer here:


   

I'm trying to redirect new Window event to a new tab:



myWebBrowser.NewWindow += add_NewTab; //...private void add_NewTab(object sender, CancelEventArgs e){     WebBrowser thisWebBrowser = (WebBrowser)sender;    e.Cancel = true; //should block the default browser to open a new window    TabPage addedTabPage = new TabPage("redirected tab"); //create a new tab    tabControl_webBrowsers.TabPages.Add(addedTabPage); //add the new tab to the TabControl    WebBrowser addedWebBrowser = new WebBrowser() //create the new web browser inside the new tab    {        Parent = addedTabPage,        Dock = DockStyle.Fill    };    addedWebBrowser.Navigate(thisWebBrowser.StatusText.ToString()); //set the new browser destination url}


I'm not sure that using WebBrowser.StatusText is the best way to obtain the new window url (this doesn't work for every site I've tested).



Is there a better class/method to call to get new window destination instead?






UPDATE:



I've tried the solution suggested by Charlie




  1. added the Microsoft Internet Control (COM) reference

  2. added using SHDocVw;

  3. used the code:



    System.Windows.Forms.WebBrowser myWebBrowser = new System.Windows.Forms.WebBrowser();

    SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)myWebBrowser.ActiveXInstance;

    axBrowser.NewWindow3 += new DWebBrowserEvents2_NewWindow3EventHandler(Browser_NewWindow3);




Unfortunately I've received a NullReference Exception on third line that I wasn't able to correct.






SOLUTION:



I don't think the solution is in the related answer (or I wasn't able to find it) because it explains how to implement the NewWindow2 event (instead of NewWindow3 which handles the original destination url) and the implementation is the same suggested here which leads to the NullReference Exception error.

Anyway I've discovered this two posts:





The suggest is to modify the previous three lines into this one:



(myWebBrowser.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Browser_NewWindow3);


Everything is working now and I was able to keep using the original System.Windows.Forms.WebBrowser in all the rest of the code.


   
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Using ActiveX Controls in .NET Applications | The Essentials for Using COM in Managed Code | InformI
[转]当用webBrowser1加载网页的时候,网页中出现js错误,会弹出一个提示,如何屏蔽不提示?
MOX.cc [vb.net中webBrowser控件的问题?如何使弹出的网页在 本身 w...
C# webBrowser控件使用心得
WebBrowser控件的常用方法、属性和事件
人生如梦,你我皆过客,来去匆匆......
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服