alert()的功能_移动端控件(一)-弹窗(Alert/Dialog)

07fa9eed394eb55b2bbd5548d7f0776f.png

什么是弹窗?

(注:本文所说的“弹窗”仅指Alert 和 Dialog,不包含Actionbar、Toast、Snackbar、Popover)

官方解释:

Dialogs inform users about a task and can contain critical information, require decisions, or involve multiple tasks. —— https:// material.io/components/ dialogs/# Alerts convey important information related to the state of your app or the device, and often request feedback. An alert consists of a title, an optional message, one or more buttons, and optional text fields for gathering input. Aside from these configurable elements, the visual appearance of an alert is static and can’t be customized. —— iOS Human Interface Guidelines
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CEF是指Chromium Embedded Framework,它是一个开源的嵌入式Web浏览器件库。在使用CEF时,我们可以通过实现OnJSDialog方法来拦截js层的alert。具体方法如下: 1. 继承CefJSDialogHandler类并实现OnJSDialog方法,该方法会在js层调用alert方法时被触发。 2. 在OnJSDialog方法中,我们可以通过调用CefJSDialogCallback的方法来自定义显示内容。 3. 在CefBrowserSettings中设置dialog_handling属性为true,以启用自定义处理。 下面是一个示例代码: ``` class MyJSDialogHandler : public CefJSDialogHandler { public: virtual bool OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin_url, const CefString& accept_lang, JSDialogType dialog_type, const CefString& message_text, const CefString& default_prompt_text, CefRefPtr<CefJSDialogCallback> callback, bool& suppress_message) override { if (dialog_type == JSDIALOGTYPE_ALERT) { // 自定义处理逻辑 CefString new_message_text = "这是一个自定义的alert:" + message_text; callback->Continue(true, new_message_text, ""); return true; } return false; } }; CefRefPtr<CefBrowser> browser = ...; // 创建浏览器实例 CefRefPtr<CefJSDialogHandler> dialog_handler = new MyJSDialogHandler(); CefBrowserSettings browser_settings; browser_settings.dialog_handling = STATE_ENABLED; browser->GetHost()->SetJSDialogHandler(dialog_handler); browser->GetHost()->SetBrowserSettings(browser_settings); ``` 通过以上步骤,我们就可以实现拦截js层的alert并自定义处理了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值