Xilium.CefGlue如何使用返回值执行JavaScript? [英] Xilium.CefGlue how to execute JavaScript with return Value?
问题描述
我在编程多线程很新,我无法从xelium例子明白我怎么能执行一个JavaScript并获得返回值。
我已经测试:
I'm quite new in programming multi-threading and I could not understand from the xelium example how I could execute a javascript and get the return value. I have tested:
browser.GetMainFrame().ExecuteJavaScript("SetContent('my Text.')", null, 0);
JavaScript的执行,但我这个功能不会让我得到的返回值。
我需要执行下面的函数来获取所有的用户都写在盒子..
the javascript is executed, but I this function don’t allow me to get the return value. I should execute the following function to get all the text the user have written in the box..
browser.GetMainFrame().ExecuteJavaScript("getContent('')", null, 0);
功能 TryEval
应该这样做...
browser.GetMainFrame().V8Context.TryEval("GetDirtyFlag", out returninformation , out exx);
但这个功能不能从浏览器调用,我认为它必须从渲染器中调用?我该怎么办呢?
But this function can’t be called from the browser, I think it must be called from the renderer? How can I do so?
我不明白关于 CefRenderProcessHandler
的解释和 OnProcessMessageReceived
..如何注册一个脚本化的对象,并设置我的JavaScript和放大器;参数?
I couldn’t understand the explanations about CefRenderProcessHandler
and OnProcessMessageReceived
.. How to register a Scriptable Object and set my javascript & parameters?
THX的任何建议,我怎么能解决这个问题!
Thx for any suggestions how I could solve this!
推荐答案
看看这篇文章: https://groups.google.com/forum/ !#话题/ cefglue / CziVAo8Ojg4
using System;
using System.Windows.Forms;
using Xilium.CefGlue;
using Xilium.CefGlue.WindowsForms;
namespace CefGlue3
{
public partial class Form1 : Form
{
private CefWebBrowser browser;
public Form1()
{
InitializeCef();
InitializeComponent();
}
private static void InitializeCef()
{
CefRuntime.Load();
CefMainArgs cefArgs = new CefMainArgs(new[] {"--force-renderer-accessibility"});
CefApplication cefApp = new CefApplication();
CefRuntime.ExecuteProcess(cefArgs, cefApp);
CefSettings cefSettings = new CefSettings
{
SingleProcess = false,
MultiThreadedMessageLoop = true,
LogSeverity = CefLogSeverity.ErrorReport,
LogFile = "CefGlue.log",
};
CefRuntime.Initialize(cefArgs, cefSettings, cefApp);
}
private void Form1_Load(object sender, EventArgs e)
{
browser = new CefWebBrowser
{
Visible = true,
//StartUrl = "http://www.google.com",
Dock = DockStyle.Fill,
Parent = this
};
Controls.Add(browser);
browser.BrowserCreated += BrowserOnBrowserCreated;
}
private void BrowserOnBrowserCreated(object sender, EventArgs eventArgs)
{
browser.Browser.GetMainFrame().LoadUrl("http://www.google.com");
}
}
}
using Xilium.CefGlue;
namespace CefGlue3
{
internal sealed class CefApplication : CefApp
{
protected override CefRenderProcessHandler GetRenderProcessHandler()
{
return new RenderProcessHandler();
}
}
internal sealed class RenderProcessHandler : CefRenderProcessHandler
{
protected override void OnWebKitInitialized()
{
CefRuntime.RegisterExtension("testExtension", "var test;if (!test)test = {};(function() {test.myval = 'My Value!';})();", null);
base.OnWebKitInitialized();
}
}
}
这篇关于Xilium.CefGlue如何使用返回值执行JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!