<script type="text/javascript">
$.extend(Engine.api,{
Push:function(_){
datapipe.torrents["t"+_.id].des = _.des;
datapipe.torrents["t"+_.id].added = _.reg;
datapipe.torrents["t"+_.id].own = _.own;
datapipe.torrents["t"+_.id].tool = _.tool;
detail.preview(_.id);
},
Oarrive:function(){
var dataStracture = "<h2>Search results</h2><h2>Nothing found!</h2><p>Try again with a refined search string.</p>";
$('#torrenttable').html(dataStracture);
dataStracture = "";
},
arrive:function(_){
//console.log("arrive called");
var hd = _.head;
var type = [1,2,2,2,2];
//console.log("Bingo on head.");
type[hd.id] = hd.type;
//console.log("head set.");
datapipe.torrents = {};
//console.log("Datapipe reseted.");
var dataStracture = "<table id='ttable' class='movehere' border='0' cellspacing='0' cellpadding='5'><tr class='thead'><td>Type</td><td class='tname' onClick=\"change('"+hd.old+"s=1&t="+type[0]+"');\">Name</td><td><img src='http://ift.tt/1BES6kD' title='Download as .torrent file' /></td><td><img src='http://ift.tt/1D2q1iy' title='Download as .txt file' /></td><td onClick=\"change('"+hd.old+"s=2&t="+type[1]+"');\">Com.</td><td onClick=\"change('"+hd.old+"s=3&t="+type[2]+"');\">Size</td><td onClick=\"change('"+hd.old+"s=4&t="+type[3]+"');\">Seeders</td><td onClick=\"change('"+hd.old+"s=5&t="+type[4]+"');\">Leechers</td></tr>";
//console.log("Bingo on start.");
var c = false;
$.each(_.torrents,function(){
datapipe.torrents["t"+this.id] = this;
//console.log("datapipe pushed: "+datapipe.torrents["t"+this.id].name);
c = c ? false : true;
dataStracture += "<tr id='tr"+this.id+"' class='trows"+(c?" tcolor":"")+"'><td><a class='_cat' id='"+this.cat+"' href='/browse.php?#/browse.php?&cata=yes&cat="+this.cat+"'><img src='"+this.cat_pic+"' border=0 /></a></td><td class='tname'><a class='T_detail' id='"+this.id+"' href='details.php?id="+this.id+"'>"+(this.New?"<b>":"")+this.name+"</b></a>"+(this.free?" <span class='tag"+this.id+" tags free'>Freeleech</span>":"")+(this.New?" <span class='tags newtags'>NEW!</span>":"")+"<br />Uploaded: "+this.added+"</td><td><a href='download.php/"+this.id+"/"+this.fname+"'><img src='http://ift.tt/1BES6kD' title='Download as .torrent file' border='0' /></a></td><td><a href='downloadtxt.php/"+this.id+"/"+this.tname+"'><img src='http://ift.tt/1D2q1iy' title='Download as .txt file' border='0' /></a></td><td>"+(this.comment?"<a href='details.php?id="+this.id+"&tocomm=1'><b id='cr"+this.id+"'>"+this.comment+"</b></a>":"<zek id='cr"+this.id+"'>0</zek>")+"</td><td>"+this.size.replace(' ','<br />')+"</td><td>"+(this.seed?"<b>"+this.seed+"</b>":"0")+"</td><td>"+(this.leech?"<b>"+this.leech+"</b>":"0")+"</td></tr>";
});
$('#torrenttable').html(_.pager+dataStracture+"</table>"+_.pager);
dataStracture = "";
},
comments:function(_){
var dataStracture = '';
$.each(_.comments,function(){
dataStracture += datapipe.templates.comment(this);
});
$('#comment-table ul').append(dataStracture).parent().append(_.pager);
dataStracture = "";
},
commentbox:function(_){
$('#details').append(_+'<div id="comment-table"><ul class="clearfix"></ul></div>');
},
comment:function(_){
_['clas'] = 'hidden';
dataStracture = datapipe.templates.comment(_);
datapipe.torrents["t"+lock].comment++;
$('#T_comment .btn span').text(datapipe.torrents["t"+lock].comment);
$('#cr'+lock).html($('#cr'+lock).text()=='0'?"<a href='details.php?"+lock+"&tocomm=1'><b id='cr"+lock+"'>"+datapipe.torrents["t"+lock].comment+"</b></a>":datapipe.torrents["t"+lock].comment);
$('#comment-table ul').prepend(dataStracture).children().first().slideDown().removeClass('hidden');
$('#tcombox').val('');
},
del:function(_){
datapipe.torrents["t"+lock].comment--;
$('#T_comment .btn span').text(datapipe.torrents["t"+lock].comment);
$('#cr'+lock).text(datapipe.torrents["t"+lock].comment);
$('#li-comment-'+_).slideUp(function(){$(this).remove()});
},
edit:function(_){
$('#li-comment-'+_.id+' .comment-body').empty().html(_.box);
$('#li-comment-'+_.id+' .tools').prepend('<div id="'+_.id+'" class="save"></div>');
},
save:function(_){
$('#li-comment-'+_.id+' .comment-body').empty().html('<p>'+_.text+'</p>');
$('#li-comment-'+_.id+' .tools').prepend('<div id="'+_.id+'" class="edit"></div>');
},
free:function(_){
datapipe.torrents["t"+lock].free = _.a;
$('#free').replaceWith(_.link);
if(_.a == 1)
$('#tr'+lock+' .T_detail, #details #tname').after(" <span class='tag"+lock+" tags free'>Freeleech</span>");
else
$('.tag'+lock).remove();
},
tags:function(){
$(".newtagsbut").remove();
$('.newtags').fadeOut('slow');
},
files:function(_){
var dataStracture = "<div id='files'><table border='1' cellspacing='0' cellpadding='5'><tr><td width='690'>Path</td><td width='60' align='right'>Size</td></tr>";
$.each(_,function(){
dataStracture += "<tr><td>"+this.path+"</td><td align='right'>"+this.size+"</td></tr>";
});
$('#desc').after(dataStracture+"</table></div>");
$('html, body').animate({scrollTop:$("#files").offset().top},(nA?400:1));
dataStracture = "";
}
});
</script>
webBrowser1.DocumentCompleted += (s, exx) =>
{
switch (webBrowser1.ReadyState)
{
case WebBrowserReadyState.Complete:
{
html = webBrowser1.Document.InvokeScript("arrive:function(_)").ToString();
break;
}
}
};
webBrowser1.DocumentCompleted += (s, exx) =>
{
switch (webBrowser1.ReadyState)
{
case WebBrowserReadyState.Complete:
{
html = webBrowser1.Document.InvokeScript("arrive:function(_)").ToString();
break;
}
}
};
I am using the webBrowser control in c# to load a webpage and need to call a Jquery function that returns a string value. I got a solution to use the InvokeScript method, and i tried a lot , but everything got failed I want Webbrowser.InvokeScript() execute arrive:function() but value return always null I do not any knowledge about Jquery so I would tried Help me, please !!!
UPDATED!!!!!!!!!!!!!
private void RegisterJsFunction(string function)
{
// Your WebBrowser control and document
var htmlDocument = this.webBrowser1.Document;
if (htmlDocument != null)
{
HtmlElement head = htmlDocument.GetElementsByTagName("head")[0];
HtmlElement scriptEl = htmlDocument.CreateElement("script");
if (scriptEl != null)
{
IHTMLScriptElement element = (IHTMLScriptElement) scriptEl.DomElement;
element.text = function;
head.AppendChild(scriptEl);
}
}
}
private string InvokeJsFunction(string functionName)
{
string html = string.Empty;
Action action = () =>
{
// Your control and document
var htmlDocument = this.webBrowser1.Document;
if (htmlDocument != null)
{
html=htmlDocument.InvokeScript(functionName).ToString();
}
};
if (this.InvokeRequired) this.Invoke(action);
else action();
return html;
}
string html = string.Empty;
webBrowser1.DocumentCompleted += (s, exx) =>
{
switch (webBrowser1.ReadyState)
{
case WebBrowserReadyState.Complete:
{
RegisterJsFunction("function foo(){Engine.api.arrive();}");
html=InvokeJsFunction("foo"); //object reference not set to an instance of an object
break;
}
}
};
I updated my code follow your code( @dyatchenko ) but I got a error:"object reference not set to an instance of an object" at line html=InvokeJsFunction("foo"); please, can you help me at this error !!
Aucun commentaire:
Enregistrer un commentaire