리눅스맨

[Solved] C# webbrowser NewWindow to Chrome Browser

C# webbrowser NewWindow to Chrome Browser

(C# 웹브라우저 새창 열릴때 크롬브라우저로 실행방법)

If you click on a specific URL to open a new window, you will be able to receive the results from the Chrome browser.

(특정 URL을 클릭 하여 새창이 뜰 경우 크롬브라우저로 그 결과값을 받을 수 있도록 만드는 로직입니다.)

  private void webBrowser1_NewWindow(object sender, System.ComponentModel.CancelEventArgs e)
        {

                HtmlElement htmlElement = webBrowser1.Document.ActiveElement;
                string getUrl = htmlElement.GetAttribute("href");
                if (getUrl.Equals(""))
                {
                    e.Cancel = false;
                    return;
                }
                if (getUrl.StartsWith("//"))
                {

                }
                else if (getUrl.StartsWith("/"))
                    getUrl = webBrowser1.Url.Host + System.Web.HttpUtitlity.UrlDecode(getUrl);

                // Here you have the ready for navigation URL.
                // chrome browser exec

                Process process = new Process();
                process.StartInfo.FileName = "chrome.exe";

                process.StartInfo.Arguments = getUrl + " --new-window";

                process.Start(); 


게시됨

카테고리

작성자

태그:

“이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.”