我正在尝试在 Content Grabber 中使用 C# 调用 Javascript 函数。(Content Grabber 是一个网页抓取软件)。
Javascript代码是这样的:
$.definePage({
idRecaptcha: null,
init: function() {},
carregarReCaptcha: function() {
if(page.idRecaptcha == null) {
var sitekey = $("#reCaptchaPublicKey").val();
page.idRecaptcha = grecaptcha.render($("#tecRecaptcha")[0], {
'callback' : page.verifyCallback,
'sitekey': sitekey
});
}
},
verifyCallback: function(response) {
if(response) {
$("#form").submit();
}
}
});
var onloadCallback = function() {
page.carregarReCaptcha();
}
我要调用的函数是“verifyCallback”。这个函数本质上是提交recaptcha token,它将验证我输入的token是否正确。
在我的 Content Grabber 代理中,我想调用这个函数,我有这个代码,但它给了我一个错误:
using System;
using System.Web.UI;
using Sequentum.ContentGrabber.Api;
public class Script
{
//See help for a definition of CustomScriptArguments.
public static CustomScriptReturn CustomScript(CustomScriptArguments args)
{
// retrieve page from current handler
var page = System.Web.HttpContext.Current.CurrentHandler as Page;
if (page == null)
{
// do something, e.g. throw exception
return CustomScriptReturn.Pause();
}
// Place your script code here.
// Return empty for no special action.
string response = args.DataRow["Captcha"];
string script = "page.verifyCallback('" + response + "');";
// call ClientScript from existing page instance
page.ClientScript.RegisterStartupScript(page.GetType(), "page.verifyCallback", script, true);
return CustomScriptReturn.Empty();
}
}
当我编译它时,它返回此错误:
Object reference not set to an instance of an object.
看来我不能只删除object sender, EventArgs e
我对 JS 或 C# 不是很熟悉,所以如果能得到任何帮助,我将不胜感激。太感谢了!