- C# 프로그램에서 Javascript function 코드 실행하는 방법
- ASP.NET이 아닌 WinForm에서 실행하는 방법

폼에 WebBrowser 콘트롤 추가

//함수 설정
	webBrowser1.DocumentText =
    @"<html><head>
      <script type='text/javascript'>
      function testFunction(text1) {
          alert(text1+' add');
      }
      </script>
      </head><body></body></html>";
            webBrowser1.Document.InvokeScript("testFunction");


//함수 호출
		object[] o = new object[1];   o[0] = txtMessage.Text;            
		object result = this.webBrowser1.Document.InvokeScript("testFunction", o);



//-------------
//참고
https://stackoverflow.com/questions/1988300/is-it-possible-to-call-javascript-method-from-c-sharp-winforms

https://www.codeproject.com/Tips/127356/Calling-JavaScript-function-from-WinForms-and-vice

 

Posted by 코덴스

댓글을 달아 주세요