CEF开发如果不想在弹出窗口中打开网页,即想要在当前窗体加载目标Url,
就需要重写OnBeforePopup,它是属于CefLifeSpanHandler类中的.

/*--cef(optional_param=target_url,optional_param=target_frame_name)--*/
bool SimpleHandler::OnBeforePopup(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
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就可以禁止创建新窗口。
本文介绍在CEF开发中如何通过重写OnBeforePopup方法来阻止浏览器在新窗口或新标签页中打开链接,实现目标Url在当前窗口加载。
1万+

被折叠的 条评论
为什么被折叠?



