Windows2020. 5. 6. 14:56

CEF#에서 alert, confirm, prompt등의 dialog를 커스텀하는 방법에 대해 정리한다.

 

IJsDialogHandler인터페이스를 구현한 객체를 ChromiumWebBrowser의 JsDialogHandler에 대입한다.

 

예)

browser.JsDialogHandler = new MyJsDialogHandler();

 

JsDialogHandler의 구현체에서는 OnJSDialog를 오버라이드 한다.

 

public bool OnJSDialog(IWebBrowser chromiumWebBrowser,

  IBrowser browser, string originUrl, CefJsDialogType dialogType,

  string messageText, string defaultPromptText,

  IJsDialogCallback callback, ref bool suppressMessage) 

{

  switch(dialogType)

  {

    case CefJsDialogType.Alert: // alert

      MessageBox.Show(messageText, "Notice", MessageBoxButton.OK);

      callback.Continue(true);

      return true;

    case CefJsDialogType.Confirm: // confirm

      var result = MessageBox.Show(messageText, "Notice", MessageBoxButton.YesNo, MessageBoxImage.Warning);

      callback.Continue(result == MessageBoxResult.Yes);

      return true;

  }

  return false;

}

Posted by 삼스