Passing Javascript Variable to Objective-C -
i've seen how pass objective-c variable javascript right here, passing objective c variable javascript in ios, how pass variable javascript objective-c when i'm using this:
[webview stringbyevaluatingjavascriptfromstring:@"var elems = document.body.getelementsbytagname(\"u\");" "passthisvartoobjc = elems.length;"
well, call stringly typed.
because return type of stringbyevaluatingjavascriptfromstring:
nsstring *
, either need stick using string or coercing value other (read:more usable) type.
but anyway, stringbyevaluatingjavascriptfromstring:
return value of javascript variable without problem.
the way accomplished through use of anonymous function (which in case self-executing):
nsstring *numofelements = [webview stringbyevaluatingjavascriptfromstring:@"(function() {var elems = document.body.getelementsbytagname(\"u\"); return elems.length;})();"]; //do normal stuff numofelements cast int or cool that.
Comments
Post a Comment