Skip to content

disallow disable open page in new window does not work #3403

@imcool

Description

@imcool

cefsharp opening two windows while navigating on google page but i want to open in one window
I have tried a lot but couldnt make it work :(. I want to have this second window open in same main window rather than new window.

I tried following but no luck, maybe i did something wrong as I am not good at coding :(

#600

#688

https://www.codeproject.com/Articles/1194609/Capturing-a-pop-up-window-using-LifeSpanHandler-an

can you please help me find solution so it opens in only Window no matter what button you click on any webpage

`
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;

namespace Nysus
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    ChromiumWebBrowser chrome;
    private void Form1_Load(object sender, EventArgs e)
    {
        CefSettings settings = new CefSettings();
        //Initialize
        Cef.EnableHighDPISupport();
        Cef.Initialize(settings);
        chrome = new ChromiumWebBrowser("http://www.google.com");
        this.pContainer.Controls.Add(chrome);
        chrome.Dock = DockStyle.Fill;
      
        this.FormBorderStyle = FormBorderStyle.None;
        this.WindowState = FormWindowState.Maximized;
        if (chrome.CanGoForward)
            chrome.Forward();
        if (chrome.CanGoBack)
            chrome.Back();
    }
   
    private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)
    {
        Cef.Shutdown();
    }

    public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
    {
        browser.MainFrame.LoadUrl(targetUrl);
        newBrowser = null;
        return true;
    }

}

}
`

https://i.stack.imgur.com/QWvRx.png

see in the image it opens two different Window when I click privacy or terms etc on google, I want it to open in same Window

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions