如何在 vb.net 项目/ NOT c sharp 中阻止 cefsharp 浏览器中的弹出窗口
How to block popups in cefsharp browser in vb.net project/ NOT c sharp
我已经找了一段时间了,我在 csharp 中找到了解决方案,但我无法翻译它(在我的 vb.net 应用程序中实现)。
我的唯一目标是当用户单击 link 时不会出现弹出窗口。
感谢您的帮助。
我的 vb.net 编码技能是初级水平,c sharp 没有知识。
c sharp 的工作解决方案:
using CefSharp;
using CefSharp.WinForms;
namespace popup_cefsharp
{
public partial class frm_main : Form
{
public frm_main()
{
InitializeComponent();
}
//variable
ChromiumWebBrowser chrome, chrome_popup;
private void initialize_browser()
{
try
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
//main browser
chrome = new ChromiumWebBrowser(this.txt_url.Text.Trim());
LifespanHandler life = new LifespanHandler();
chrome.LifeSpanHandler = life;
life.popup_request += life_popup_request;
this.pan_container.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
//second browser (popup browser)
chrome_popup = new ChromiumWebBrowser("");
this.pan_container_popup.Controls.Add(chrome_popup);
chrome_popup.Dock = DockStyle.Fill;
}
catch (Exception ex)
{
MessageBox.Show("Error in initializing the browser. Error: " + ex.Message);
}
}
private void carregar_popup_new_browser(string url)
{
//open pop up in second browser
chrome_popup.Load(url);
}
private void frm_main_FormClosing(object sender, FormClosingEventArgs e)
{
//close o object cef
Cef.Shutdown();
Application.Exit();
}
private void frm_main_Load(object sender, EventArgs e)
{
//initialize the browser
this.initialize_browser();
}
private void life_popup_request(string obj)
{
//function for open pop up in a new browser
this.carregar_popup_new_browser(obj);
}
}
}
link original post: https://www.codeproject.com/Articles/1194609/Capturing-a-pop-up-window-using-LifeSpanHandler-an
终于找到了解决方案,如果有人感兴趣的话
这里是 link,你需要安装 cefsharp nuggets 包,添加 lifessionhandler 作为一个新的 class,文件在 link,然后复制调用函数的方法主要形式...
干杯...
https://github.com/messi06/vb.net_CefSharp_popup
我已经找了一段时间了,我在 csharp 中找到了解决方案,但我无法翻译它(在我的 vb.net 应用程序中实现)。 我的唯一目标是当用户单击 link 时不会出现弹出窗口。 感谢您的帮助。 我的 vb.net 编码技能是初级水平,c sharp 没有知识。 c sharp 的工作解决方案:
using CefSharp;
using CefSharp.WinForms;
namespace popup_cefsharp
{
public partial class frm_main : Form
{
public frm_main()
{
InitializeComponent();
}
//variable
ChromiumWebBrowser chrome, chrome_popup;
private void initialize_browser()
{
try
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
//main browser
chrome = new ChromiumWebBrowser(this.txt_url.Text.Trim());
LifespanHandler life = new LifespanHandler();
chrome.LifeSpanHandler = life;
life.popup_request += life_popup_request;
this.pan_container.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
//second browser (popup browser)
chrome_popup = new ChromiumWebBrowser("");
this.pan_container_popup.Controls.Add(chrome_popup);
chrome_popup.Dock = DockStyle.Fill;
}
catch (Exception ex)
{
MessageBox.Show("Error in initializing the browser. Error: " + ex.Message);
}
}
private void carregar_popup_new_browser(string url)
{
//open pop up in second browser
chrome_popup.Load(url);
}
private void frm_main_FormClosing(object sender, FormClosingEventArgs e)
{
//close o object cef
Cef.Shutdown();
Application.Exit();
}
private void frm_main_Load(object sender, EventArgs e)
{
//initialize the browser
this.initialize_browser();
}
private void life_popup_request(string obj)
{
//function for open pop up in a new browser
this.carregar_popup_new_browser(obj);
}
}
}
link original post: https://www.codeproject.com/Articles/1194609/Capturing-a-pop-up-window-using-LifeSpanHandler-an
终于找到了解决方案,如果有人感兴趣的话 这里是 link,你需要安装 cefsharp nuggets 包,添加 lifessionhandler 作为一个新的 class,文件在 link,然后复制调用函数的方法主要形式... 干杯... https://github.com/messi06/vb.net_CefSharp_popup