CefSharp.Winforms通过javascript关闭选项卡 [英] CefSharp.Winforms close tab by 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
您可以挂钩 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屋!