我正在用NPAPI寫一個safari插件。 如何從NPAPI插件(不使用FireBreath)返回一個整數到JavaScript? 的javascript:如何從NPAPI插件返回一個整數到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返回一個數字()?
Plz help!
我發現這個線程: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);
放。
取決於'utf8fromidentifier'是次優的,最好使用'static const NPIdentifier id = browser-> getstringidentifier(「foo」); if(methodName == id){...'。 –