Disable pop-up browser window in CEF

Source: Internet
Author: User

When using CEF, the page that is loaded, if there is a link in it, specifies target= "_blank", a new browser window will pop up. If you want to disable, let the new page appear in the current browser window, you can rewrite the Ceflifespanhandler Onbeforepopup method in the handler of the browser process, and load the URL of the popup request with browser mainframe. The code is as follows:

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; //cancel create    }    return false;}

The first parameter of the Onbeforepopup function browser represents the browser object that issued the popup request, and the frame is the target to be loaded by the Frame,target_url that issued the popup request url,target_ Disposition is the display mode. We'll just have to take care of these parameters, load a new URL with browser mainframe for a specific number of WOD, return True, and end the process of creating a new window.

There is also some discussion about this requirement: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=196. It refers to the modification of the DOM or modified CEF source code to achieve, also can refer to.

That's it.

Other reference articles are described in my column: "CEF and Ppapi development ".

Disable pop-up browser window in CEF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.