This ilifehandler code doesnt work

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

This ilifehandler code doesnt work

Postby imcool » Fri Feb 12, 2021 8:54 am

hi all,
I am trying to disallow disable open page in new window, see in screenshot there are 2 windows opened but I want it to open only in one Window and not in two different window

I tried code from following resources but nothing works for me, can someone please help me with a solution?

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

https://github.com/cefsharp/CefSharp/issues/600

https://github.com/cefsharp/CefSharp/issues/688

https://www.codeproject.com/Articles/11 ... Handler-an


Code: Select all
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;
        }

    }
}
imcool
Newbie
 
Posts: 1
Joined: Fri Feb 12, 2021 12:29 am

Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 20 guests