简体   繁体   English

获取加载 html 页面的 url 的问题(c#)

[英]problem of getting url of loading html page (c#)

Well,出色地,

I develop a native browser and i've got a problem with a site navigated on this browser.我开发了一个本机浏览器,但在此浏览器上导航的站点出现问题。

An input["type"]-button click post an httprequest to obtain and show an other page in a new tab (onglet).输入["type"] 按钮单击发布 http 请求以获取并在新选项卡 (onglet) 中显示其他页面。

I'm trying several methods but the TabPageof webBrowser is blank and I've got a IE explorer window opening.我正在尝试几种方法,但 TabPageof webBrowser 是空白的,我有一个 IE 浏览器 window 打开。

here the code这里的代码

 private void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
        {
 webBrowser22 = (WebBrowser)sender;
            if (webBrowser22.Document != null)
            {
                foreach (HtmlElement tag in webBrowser22.Document.All)
                {
 HtmlElementCollection elements = webBrowser22.Document.GetElementsByTagName("input");

                for (int i = 0; i < elements.Count; i++)
                {
                    HtmlElement el = elements[i];
                    string elType = el.GetAttribute("type");

                    switch (elType)
                    {
                        case "radio":
                        case "checkbox":
                        case "button":
                            {
                                el.MouseUp += new HtmlElementEventHandler(link_MouseUpPup);
                                
                            }
}}}}

private void link_MouseUpPup(object sender, HtmlElementEventArgs e)
        {
            
            this.tb2 = new System.Windows.Forms.TabPage();
            this.webBrowser221 = new System.Windows.Forms.WebBrowser();
           
            var linky = (HtmlElement)sender;
            mshtml.HTMLAnchorElement ba = (mshtml.HTMLAnchorElement)linky.DomElement;

       
            //  if ((ba.target != null && ba.target.ToLower() == "_blank") || e.ShiftKeyPressed || e.MouseButtonsPressed == MouseButtons.Middle)

            //if (Regex.Match(e.ReturnValue.ToString(), "http:").Value != null || Regex.Match(e.ReturnValue.ToString(), "https:").Value != null)
            
                tabControl1.Controls.AddRange(new Control[] { this.tb2 });
                tb2.Controls.AddRange(new Control[] { this.webBrowser221 });
                webBrowser221.Dock = DockStyle.Fill;

1ERE METHODE----
                //webBrowser221.Navigate(HttpContext.Current.Request.Url.AbsoluteUri);
2EME METHODE----                
//webBrowser221.Navigate(ba.href);
3EME METHODE----
                // webBrowser221.Navigate(HttpContext.Current.Request.ServerVariables["URL"].ToString());
4EME METHODE----               
// webBrowser221.Navigate(e.ToElement.GetAttribute("onclick").ToString());
                
tb2.Text = e.ToElement.GetAttribute("onclick").ToString();
                tb2.ToolTipText = webBrowser221.StatusText;
            }

The problem is that I would opening the site page loading by the click input after his process (the process is been programmed in html and javascript with the function window.open and the property target="_blank") by the c# control webBrowser. The problem is that I would opening the site page loading by the click input after his process (the process is been programmed in html and javascript with the function window.open and the property target="_blank") by the c# control webBrowser.

who's the problem, it's ie explorer that is opening instead of webBrowser window.谁是问题所在,即打开的是浏览器而不是webBrowser window。

thanks your for your help.谢谢你的帮助。

MA

Finally,最后,

I used the package reference "SHDocVm" of "Microsoft Internet Controls" and I place a function handler NewWindow3 after the case button and it's ok, a window.open() javascript function with target="_blank" opens a new page of webBrowser. I used the package reference "SHDocVm" of "Microsoft Internet Controls" and I place a function handler NewWindow3 after the case button and it's ok, a window.open() javascript function with target="_blank" opens a new page of webBrowser.

Truly yours.肃然。

MA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM