본문 바로가기

.NET/C#

webbrowser control c# 에서 스크립트 injection하기


            // Your WebBrowser control and document

            var htmlDocument = this.webBrowser1.Document;

            if (htmlDocument != null)

            {

                HtmlElement head = htmlDocument.GetElementsByTagName("head")[0];

                HtmlElement scriptEl = htmlDocument.CreateElement("script");

                if (scriptEl != null)

                {

                    IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;

                    element.text = function; // 여기에 삽입할 function 작성

                    head.AppendChild(scriptEl);

                }

            }