• CEF 重写弹窗事件


    CEF开发想要在当前窗体加载目标url,而不想在弹出窗口中打开网页,需要重写OnBeforePopup,它是属于CefLifeSpanHandler类中。

    bool CefHandlerImpl::OnBeforePopup(CefRefPtr<CefBrowser> browser,
                                        CefRefPtr<CefFrame> frame,
                                        const CefString& target_url,
                                        const CefString& target_frame_name,
                                        CefLifeSpanHandler::WindowOpenDisposition target_disposition,
                                        bool user_gesture,
                                        const CefPopupFeatures& popupFeatures,
                                        CefWindowInfo& windowInfo,
                                        CefRefPtr<CefClient>& client,
                                        CefBrowserSettings& settings,
                                        CefRefPtr<CefDictionaryValue>& extra_info,
                                        bool* no_javascript_access)
    {
        switch (target_disposition)
        {
        case WOD_NEW_FOREGROUND_TAB:
        case WOD_NEW_BACKGROUND_TAB:
        case WOD_NEW_POPUP:
        case WOD_NEW_WINDOW:
            browser->GetMainFrame()->LoadURL(target_url);
            return true;
        }
    
        return false;
    }

    第一个参数browser代表了发出popup请求的浏览器对象。

    frame是发出popup请求的那个frame。

    target_url是要加载的目标url。

    target_disposition是显示方式(UNENOWN,当前选项卡,单例模式选项卡,新前台选项卡,新的背景选项卡,新弹出,新窗口,保存到磁盘,记录,忽视行动)。

    user_gesture表示弹窗是用户手动点击打开(true)还是自动打开(false)的。

    popupFeatures结构包含了关于请求的弹出窗口的额外信息。

    //弹窗的额外信息
    popupFeatures.height;   //弹窗的高度
    popupFeatures.width;   //弹窗的宽度
    popupFeatures.heightSet;
    popupFeatures.widthSet;
    popupFeatures.x;
    popupFeatures.y;
    popupFeatures.xSet;
    popupFeatures.ySet;
    popupFeatures.menuBarVisible;
    popupFeatures.statusBarVisible;
    popupFeatures.toolBarVisible;
    popupFeatures.scrollbarsVisible;

    client和settings值将默认为源浏览器的值。如果no_javascript_access值设置为false,则新浏览器将不能编写脚本,并且可能不会托管在与源浏览器相同的渲染进程中。

    如果父浏览器被封装在CefBrowserView中,那么对windowInfo的任何修改都会被忽略。如果父浏览器在弹出浏览器创建完成之前被销毁,弹出浏览器创建将被取消(通过调用OnAfterCreated为弹出浏览器指示)。

    extra_info参数提供了一个机会来指定特定于创建的弹出式浏览器的额外信息,这些信息将在渲染进程中传递给CefRenderProcessHandler::OnBrowserCreated()。

    返回true就可以禁止创建新窗口。

    参考于:https://www.cnblogs.com/sinceret/p/10346171.html

  • 相关阅读:
    js复习---工厂函数---构造函数的执行过程
    21年初的措不及防-------
    element ui checkbox实现多项全选反选功能
    vue 实现导航锚点联动
    this.$router.currentRoute 和 this.$route的 区别
    重置vue组件的data数据 this.$options.data()
    父组件中如何拿到引入的子组件里element-ui 的form表单ref对象
    线程笔记
    面向对象
    关于上传和下载的笔记
  • 原文地址:https://www.cnblogs.com/tingtaishou/p/14760845.html
Copyright © 2020-2023  润新知