CefSharp.Winforms通过javascript关闭选项卡 [英] CefSharp.Winforms close tab by javascript

查看:744
本文介绍了CefSharp.Winforms通过javascript关闭选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了CefSharp.WinForms.ChromiumWebBrowser v41.0.1。有许多选项卡,每个选项卡都有一个chrome webbrowser。
我尝试通过javascript函数window.close()关闭其中一个选项卡。但它也关闭了所有标签和我的程序。主要原因是什么?有没有办法通过javascript关闭一个标签?

I'm using CefSharp.WinForms.ChromiumWebBrowser v41.0.1 in my project. There are many tabs, each tab has a chromium webbrowser. I try to close one of these tabs by javascript function window.close(). But it also closes both all tabs and my program. What is the main reason? And is there any way to close only one tab by javascript?

推荐答案

我相信你会发现 CEF WM_CLOSE 消息发送到顶级窗口,因为它是默认行为。

I believe you'll find that CEF sends a WM_CLOSE message to the top level window as it's default behavior.

一种选择是升级到 43.0.0-pre02 版本,然后实现 ILifeSpanHandler.DoClose 能够返回true 来实现自己的自定义行为。
https://github.com/cefsharp /CefSharp/blob/cefsharp/43/CefSharp/ILifeSpanHandler.cs#L109

One option is to upgrade to the 43.0.0-pre02 release, then implement ILifeSpanHandler.DoClose for when you should be able to return true to implement your own custom behavior. https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp/ILifeSpanHandler.cs#L109

http://magpcss.org/ceforum/apidocs3/projects/%28default%29/CefLifeSpanHandler。 html #DoClose%28CefRefPtr%3CCefBrowser%3E%29

您可以挂钩 window.close ,使用 Javascript绑定将其绑定到方法,然后自己处理关闭。

You could possibly hook into window.close, bind it to a method using Javascript binding, then handle the close yourself.

第三个选项是看看以某种方式取消表单关闭,可能使用 FormClosing 事件。

The third option, is to look at somehow canceling the form close, maybe with the FormClosing event.

我还没有尝试任何这些选项明确地知道哪个是最简单和最干净的,我相信你可以找到一些有用的东西。

I haven't tried any of these options explicitly, to know which is the easiest and cleanest, I'm sure you can find something that works though.

这篇关于CefSharp.Winforms通过javascript关闭选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆