我正在用 NPAPI 编写一个 safari 插件。如何将整数从 NPAPI 插件(不使用 FireBreath)返回到 JavaScript?javascript:
<html>
<head>
<script>
function run() {
var plugin = document.getElementById("pluginId");
var number = plugin.getBrowserName();
alert(number);
}
</script>
</head>
<body >
<embed width="0" height="0" type="test/x-open-with-default-plugin" id="pluginId">
<button onclick="run()">run</button>
</body>
</html>
插件代码:
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
// Make sure the method called is "open".
NPUTF8 *name = browser->utf8fromidentifier(methodName);
if(strcmp(name, plugin_method_name_getBrowserName) == 0) {
//what can i do here?
}
return true;
}
如何从 plugin.getBrowserName() 返回一个数字?
请帮忙!
我找到了这个线程:Return an integer/String from NPAPI plugin to JavaScript(Not using FireBreath),但我不知道这些代码在哪里
char* npOutString = (char *)pNetscapefn->memalloc(strlen(StringVariable) + 1);
if (!npOutString) return false; strcpy(npOutString, StringVariable);
STRINGZ_TO_NPVARIANT(npOutString, *result);
放。