[英]Using EvaluateScriptAsync to call javascript in CefSharp
Currently using CefSharp in my Visual Studio project to show a web browser. 当前在我的Visual Studio项目中使用CefSharp来显示Web浏览器。 I'm using the EvaluateScriptAsync to call a function in my javascript.
我正在使用EvaluateScriptAsync在我的JavaScript中调用一个函数。
But I encounter a small problem. 但是我遇到一个小问题。
The below can work: 以下可以工作:
string strMsg = "12345";
var script = string.Format("testing({0});", strMsg);
browser.EvaluateScriptAsync(script);
The below cannot work: 以下内容不起作用:
string strMsg = "ABCDE";
var script = string.Format("testing({0});", strMsg);
browser.EvaluateScriptAsync(script);
Then on the html side: 然后在html端:
testing = function (error) {
alert(error);
return false;
};
Why is it I can't send alphabets string? 为什么我不能发送字母字符串?
Is there a difference between sending a numbers and sending alphabets? 发送数字和发送字母之间有区别吗?
The string you generate will execute as JavaScript. 您生成的字符串将作为JavaScript执行。 As it stands in your second example when the code executes it would be looking for a variable named
ABCDE
. 正如您在第二个示例中所说的那样,在代码执行时,它将寻找一个名为
ABCDE
的变量。 You need to encapsulate in quotes to make it into a string. 您需要使用引号将其封装为字符串。
string strMsg = "ABCDE";
should be 应该
string strMsg = "`ABCDE`";
or 要么
string strMsg = "\"ABCDE\"";
For debugging, CefSharp
supports DevTools
which you can open and see JavaScript console output. 对于调试,
CefSharp
支持DevTools
,您可以打开并查看JavaScript控制台输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.