npapi代码:
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
NPUTF8 *name = browser->utf8fromidentifier(methodName);
if(strcmp(name, plugin_method_name_getAddress) == 0){
NPString password;
if(argCount > 0) {
password = NPVARIANT_TO_STRING(args[0]);
}
const char * StringVariable = password.UTF8Characters;
char* npOutString = (char *)malloc(strlen(StringVariable+1));
if (!npOutString)
return false;
strcpy(npOutString, StringVariable);
STRINGZ_TO_NPVARIANT(npOutString, *result);
browser->memfree(name);
return true;
}
return false;
}
html代码:
function run() {
var plugin = document.getElementById("pluginId");
var passwordBeforEncryption = document.getElementById("passwordFeild");
if(plugin){
var value = plugin.getAddress("hello, just test it");
alert(value);
}else{
alert("plugin is null");
}
}
正确的结果应该是:“hello, just test it”,但有时会返回“hello, just test itÿÿÿÿ”。它只是有时不是所有时间!
请帮忙。