KenTien 发表于 2025-1-17 15:27:13

CEF3专辑-进阶篇-03-自定义弹窗

本帖最后由 KenTien 于 2025-3-11 08:27 编辑

一、使用浏览器默认的关闭提示框// 前端 JS 代码
window.onbeforeunload = function(){
    return "这里的提示文案,无论你写啥,都不会显示,只会显示Chrome浏览器内置的提示"}
二、使用自定义的关闭提示框,如果不处理。那也是弹窗class Client
    : public CefClient
    , public CefJSDialogHandler {
public:
    // CefClient methods:
    CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() override { return this; }

    // CefJSDialogHandler methods:
   virtual bool OnBeforeUnloadDialog(
      CefRefPtr<CefBrowser> browser,
      const CefString& message_text,
      bool is_reload,
      CefRefPtr<CefJSDialogCallback> callback) override {

      HWND hwnd = browser->GetHost()->GetWindowHandle();
      int msgboxID = MessageBox(hwnd, L"您编辑的内容尚未保存.\n确定要关闭窗口吗?", L"系统提示", MB_OKCANCEL);
      if (msgboxID == IDOK) {
      // 继续执行
            callback->Continue(true, CefString());
      } else {
            callback->Continue(false, CefString());
      }
      return true;
};





A丶 发表于 2025-2-7 13:05:22

谢谢大佬分享,学到了很多
页: [1]
查看完整版本: CEF3专辑-进阶篇-03-自定义弹窗