马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 KenTien 于 2025-3-11 08:27 编辑
一、 使用浏览器默认的关闭提示框 [JavaScript] 查看源码 复制代码 // 前端 JS 代码
window.onbeforeunload = function(){
return "这里的提示文案,无论你写啥,都不会显示,只会显示Chrome浏览器内置的提示"}
二、使用自定义的关闭提示框,如果不处理。那也是弹窗 [C++] 查看源码 复制代码 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;
};
|