浏览器CEFSharp88+X86+win7 之js交互开启(五)
编写
灵体.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true;
错误提醒
关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。
************** 异常文本 **************
System.Exception: JavascriptBindingSettings.LegacyBindingEnabled can no longer be modified, settings must be changed before the underlying browser has been created.
在 CefSharp.Internals.FreezableBase.ThrowIfFrozen(String memberName)
在 CefSharp.JavascriptBinding.JavascriptBindingSettings.set_LegacyBindingEnabled(Boolean value)
在 CyberWin.NET.Csharp.WebBrowser.Form_老多tab.东方仙盟_赋值接口(ChromiumWebBrowser 灵体)
在 CyberWin.NET.Csharp.WebBrowser.Form_老多tab.NewTab(String startUrl)
在 CyberWin.NET.Csharp.WebBrowser.Form_老多tab.toolStripButton8_Click(Object sender, EventArgs e)
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
程序集版本:4.0.0.0
Win32 版本:4.8.4795.0 built by: NET48REL1LAST_B
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
CyberWin.NET.ApplicationVOS109
程序集版本:1.0.0.0
Win32 版本:1.0.0.0
基本代码:file:///G:/%E6%9C%AA%E6%9D%A5%E4%B9%8B%E7%AA%97%E6%BA%90%E7%A0%81%E5%A4%87%E4%BB%BD/visaulstudio/CyberWin.NET.ApplicationVOS109/packages/%E6%9C%AA%E6%9D%A5%E4%B9%8B%E7%AA%9788%E6%89%93%E5%8C%85/CyberWin.NET.ApplicationVOS109.exe
----------------------------------------
System.Windows.Forms
程序集版本:4.0.0.0
Win32 版本:4.8.4739.0 built by: NET48REL1LAST_B
基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
在使用诸如 CefSharp
(一个用于在.NET 应用程序中嵌入 Chromium 浏览器的库)之类的框架时,你提到的代码 webview.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true;
具有以下含义:
JavascriptObjectRepository
:这是CefSharp
中用于管理在 JavaScript 和.NET 之间共享对象的存储库。通过这个存储库,你可以将.NET 对象暴露给 JavaScript 代码,使得 JavaScript 能够调用.NET 对象的方法、访问其属性等,实现双向通信。Settings
:它表示JavascriptObjectRepository
的设置集合,其中包含了各种配置选项,用于控制对象绑定的行为。LegacyBindingEnabled
:这是Settings
中的一个布尔属性。当设置为true
时,它启用了旧版绑定模式。在旧版绑定模式下:- 命名约定:JavaScript 访问.NET 对象的属性和方法时,使用的命名约定相对简单直接。例如,如果有一个.NET 类
MyClass
具有属性MyProperty
和方法MyMethod
,在 JavaScript 中可以直接以相同的名称访问它们。 - 兼容性:这种模式有助于与旧版代码或不严格遵循最新最佳实践的代码保持兼容性。例如,一些早期编写的 JavaScript 代码可能依赖于这种简单的命名映射来与.NET 对象进行交互。
- 命名约定:JavaScript 访问.NET 对象的属性和方法时,使用的命名约定相对简单直接。例如,如果有一个.NET 类
然而,启用旧版绑定模式也可能带来一些潜在的问题,例如可能存在命名冲突的风险,并且从长远来看,可能不符合最新的安全或设计标准。在新的开发中,可能更推荐使用更现代、安全和灵活的绑定方式,但在某些特定场景下,启用此选项可以解决兼容性问题。
总之,这行代码的作用是启用 JavascriptObjectRepository
的旧版绑定模式,以便 JavaScript 能够以特定的旧版方式与.NET 对象进行交互
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.