【CEF3学习】– 在同一窗口打开链接
本次着手实现将 target="_blank“的行为修改为 target="_self"。 CEF3提供了UI窗口生命周期接口 CefLifeSpanHandler,借助这个接口来监听新窗口创建事件,并在创建前取消窗口创建,使用已有窗口来加载新链接。 class CefLifeSpanHandler : public virtual CefBaseRefCounted { public: ///由UI线程调用,调用时机是新浏览窗口创建前。 // frame 弹出新窗口链接的源frame(即从哪个frame里的链接弹出新窗口) // target_url 目的链接 // target_frame_name 目的frame名字 // 返回true,则表示要取消窗口创建 virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, const CefString& target_frame_name, WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, CefRefPtr& extra_info, bool* no_javascript_access) { frame->LoadURL(target_url); //在当前frame中加载链接 return true; //返回true,取消窗口创建 }