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是显示方式。
返回true就可以禁止创建新窗口。
转载于:https://www.cnblogs.com/sinceret/p/10346171.html
原文:https://www.cnblogs.com/tingtaishou/p/14760845.html