C# WebBrowser 取 window.open 新窗口 url的方法
生活随笔
收集整理的這篇文章主要介紹了
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;}
總結
以上是生活随笔為你收集整理的C# WebBrowser 取 window.open 新窗口 url的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光大金服是什么公司
- 下一篇: 罗福兴(说一说罗福兴的简介)