Cef 重写alert与confirm弹窗

时间:2022-04-10 23:18:12

在使用form内嵌cef浏览本地页面的时候,如果出现alert弹窗,会在标题栏显示页面所在目录。所以想起来重写alert的样式,通过MessageBox进行提示,或者自己写一个弹窗。

Cef 重写alert与confirm弹窗

以下代码基于 3.2623.1401.gb90a3be 也就是最后一个兼容xp的版本

procedure Tfrm.Chromium1Jsdialog(Sender: TObject;
const browser: ICefBrowser; const originUrl, acceptLang: ustring;
dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
var
m: ustring;
begin
inherited; case dialogType of
JSDIALOGTYPE_ALERT:
begin
GLB.ShowMsgBoxWarning(messageText, defaultPromptText);
suppressMessage:=True;
Result:=False;
end;
JSDIALOGTYPE_CONFIRM:
begin
callback.Cont(GLB.ShowMsgBoxQuery(messageText, defaultPromptText)=mrYes, m);
suppressMessage:=False;
Result:=True;
end;
// JSDIALOGTYPE_PROMPT: //输入框;
end;
end;