Could anyone please explain with a sample...?
How can I return an integer/String from NPAPI plugin(Not using FireBreath) to JavaScript?
I searched a lot ..but can't get a relevant answer.
Asked
Active
Viewed 670 times
1

Akhil
- 1,073
- 1
- 9
- 28
2 Answers
2
You need to make a Scriptable class of NPObject: Simple class definition and implementation
You can this post use in Firefox/Chrome browser. Its very similar to your question and has code for the invoke and the JavaScript/html. here.
If you have not read through at least part 1-3 of taxillian's blog on plugins, I would say it is a must read. Read carefully a lot of info I have missed by skimming by when reading.

Community
- 1
- 1

hapyfishrmn
- 177
- 2
- 21
-
As he says; in particular you need to create a NPVariant with the value you want. int32 is easy (see http://code.google.com/p/npapi-sdk/source/browse/trunk/headers/npruntime.h#155 for a helper macro), string is slightly harder because you need to allocate the string using NPN_MemAlloc. See http://npapi.com/memory – taxilian Oct 12 '12 at 02:57
-
Thanks..I just returned an integer value. One more thing is I just want to return a char array to javaScript. How can it possible? char Map[50][50] = {0}; this is that array..I read your tutorials,I can't use fireBreath because of some dependency issues with binaries. so I'm a newbie to NPAPI. Hope you will help.. Could you place some sample? – Akhil Oct 12 '12 at 12:52
-
I have not returned an array personally, but this seems to be you same question: http://stackoverflow.com/questions/12078250/return-array-from-npapi-plugin-to-java-script – hapyfishrmn Oct 12 '12 at 20:53
2
Found a solution.
Returning a string from NPAPI plugin
char* npOutString = (char *)pNetscapefn->memalloc(strlen(StringVariable) + 1);
if (!npOutString)
return false;
strcpy(npOutString, StringVariable);
STRINGZ_TO_NPVARIANT(npOutString, *result);

Akhil
- 1,073
- 1
- 9
- 28