CefGlue现有解决方案:Call .Net from javascript in CefSharp 1 - wpf
我完全想要这个,但是对于CefGlue:我想使用JavaScript与App进行通信。因此,当我单击HTML站点中的按钮时,我希望应用程序处理此问题(例如:启动tcp服务器)。
我尝试注册自己的CefV8Handler,但没有成功,从未调用处理程序上的Execute函数。这是我现在所做的
protected override void OnWebKitInitialized()
{
Console.WriteLine("Registering testy extension");
Xilium.CefGlue.CefRuntime.RegisterExtension("testy", "var testy;if (!testy)testy = {};(function() {testy.hello = function() {};})();", new V8Handler());
base.OnWebKitInitialized();
}
我的V8Handler代码如下所示:
public class V8Handler : Xilium.CefGlue.CefV8Handler
{
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
{
if (name == "testy")
Console.WriteLine("CALLED TESTY");
else
Console.WriteLine("CALLED SOMETHING WEIRED ({0})", name);
returnValue = CefV8Value.CreateNull();
exception = null;
return true;
}
}
我处于多进程模式,没有控制台窗口显示“ CALTED TESTY”或“ CALLED SOMETHING WEIRED”。
参考方案
找到了解决方案。诀窍是创建一个CefV8Value(CreateFunction)并将其分配给V8Handler。然后将此值分配给全局上下文。看起来是这样的:
internal class RenderProcessHandler : CefRenderProcessHandler
{
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
{
CefV8Value global = context.GetGlobal();
CefV8Value func = CefV8Value.CreateFunction("magic", new V8Handler());
global.SetValue("magic", func, CefV8PropertyAttribute.None);
base.OnContextCreated(browser, frame, context);
}
}
另一个问题出现了:它在渲染器过程中被调用,但是我需要在浏览器过程中进行回调。在CefV8Handlers执行函数中,我这样做:
var browser = CefV8Context.GetCurrentContext().GetBrowser();
browser.SendProcessMessage(CefProcessId.Browser, CefProcessMessage.Create("ipc-js." + name));
这样,我可以在CefClient实现的OnProcessMessageReceived函数中检索消息。
javascript popupwindow之后的行如何工作? - javascript好的,我有一个来自后面代码的方法,可以创建一个popupwindow。然后有一行代码要在那之后执行,我想知道那行代码何时执行,是在使用popupwindow之后执行还是在创建popupwindow之后执行?例如:void exPopupWindowMethod() { string scr = "window.open('exampleP…
ddl在服务器中未更新-asp.net - javascript我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……
.NET C#Webbrowser填充输入,不带ID或类名 - javascript我需要在网络浏览器中填写一个输入,但这不起作用。我认为必须使用name属性来完成,但是怎么做呢?foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input")) { if (login.GetAttribute("name"…
获取JavaScript值到C#字符串 - javascript是否可以在C#中执行类似的操作?该值为“ 10/05/2014”string jsValue = javascript("$('#EstimatedStartDate').val()"); 参考方案 您能否更详细地阐明您要做什么。看来您正在尝试从javascript(客户…
如何使用JavaScript访问嵌入式ASP.NET GlobalResources? - javascript我正在开发一个遗留的ASP.NET项目,该项目正试图缓慢地进行调整,但是如果没有像巧克力手指屋一样塌陷的情况,我将无法进行重大更改。我试图为此找到解决方案,但由于术语的特定混合(“ javascript”,“ embedded”和/或“ resource”只是为我提供了有关如何嵌入.js文件的信息,而失败了)。 。),这可能是一种怪异的处理方式。该项目将Ap…