zoukankan      html  css  js  c++  java
  • C# WebBrowser 取 window.open 新窗口 url的方法

    System.Windows.Forms.WebBrowser wb;       //WebBrowser 对象
    
                wb.NewWindow += new CancelEventHandler(wb_NewWindow);
                wb.DocumentCompleted += delegate
                {               
                    #region 处理window.open新开窗口的问题
    
                    System.Windows.Forms.HtmlElement html = wb.Document.CreateElement("div");
                    html.InnerHtml += "<a id="popLink" href="" target="_blank" style="display:none;"></a>";
                    wb.Document.Body.AppendChild(html);
    
                    string jsHtml = "";
                    jsHtml += "window.open=function(url, title, prop)  ";
                    jsHtml += "{";
                    jsHtml += "obj = document.getElementById('popLink');  ";
                    jsHtml += "obj.style.display='block';  ";
                    jsHtml += "obj.href=url;  ";
                    jsHtml += "obj.focus();  ";
                    jsHtml += "obj.click();  ";
                    jsHtml += "obj.style.display='none'  ";
                    jsHtml += "} ";
                    mshtml.IHTMLDocument2 doc = wb.Document.DomDocument as mshtml.IHTMLDocument2;
                    mshtml.IHTMLWindow2 win = doc.parentWindow as mshtml.IHTMLWindow2;
                    win.execScript(jsHtml, "javascript");
    
                    #endregion
    
                };
    
    
            static void wb_NewWindow(object sender, CancelEventArgs e)
            {
                System.Windows.Forms.WebBrowser web = (System.Windows.Forms.WebBrowser)sender;
                string newUrl = web.StatusText.ToString();
                showNewWinWithUrlInner(null, newUrl, "", 800, 600, true, false);//自己取到新窗口url后自行处理
                e.Cancel = true;
            }
    

      

  • 相关阅读:
    计算两个经纬度之间的距离,单位米
    PHP获取汉字首字母函数
    tp3.2 上传文件及下载文件
    最少知识原则
    单一职责原则
    接口和面向接口编程
    开放-封闭原则
    设计原则
    websrom编译器
    头条笔试题2018后端第二批-用户喜好
  • 原文地址:https://www.cnblogs.com/soundcode/p/13689607.html
Copyright © 2011-2022 走看看