Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:43:31+00:00 2026-06-15T11:43:31+00:00

I am writing a safari plugin with NPAPI. How can I return an integer

  • 0

I am writing a safari plugin with NPAPI.
How can I return an integer from NPAPI plugin(Not using FireBreath) to 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>

plugin code:

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;

}

How to return a number from plugin.getBrowserName()?

Plz help!

I am find this thread:Return an integer/String from NPAPI plugin to JavaScript(Not using FireBreath),
but i don’t know where are these code

char* npOutString = (char *)pNetscapefn->memalloc(strlen(StringVariable) + 1);
if (!npOutString) return false; strcpy(npOutString, StringVariable); 
STRINGZ_TO_NPVARIANT(npOutString, *result);

put.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:43:33+00:00Added an answer on June 15, 2026 at 11:43 am

    Have you looked at http://npapi.com/tutorial3?

    The return value goes in the NPVariant* result. Go look at the docs for NPVariant and you’ll see there is a type and then a union for different types of data. The string code you’re talking about would go in place of your “//what can i do here?” comment. To return an integer, you’d do this:

    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) {
      result->type = NPVariantType_Int32;
      result->intValue = 42;
    }
    return true;
    

    You can also use the *_TO_NPVARIANT macros (documented at the link above for NPVariant docs) like so:

    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) {
      INT32_TO_NPVARIANT(42, *result);
    }
    return true;
    

    If you look at the source for the INT32_TO_NPVARIANT macro you’ll see it just does the same thing I did above, so the two are equivilent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing htaccess that allows me to remove index.php from the URL can confuse search
I'm writing a python script that generates html file. Every time I run this
Writing a script to automatically create an appointment in outlook via javascript. It works
When writing pixels to an HTML Canvas context using putImageData I find that the
I am writing a Safari extension. It needs to overlay content from another source
Writing documentation in html requires some code examples. What to do with characters that
Writing a python program, and I came up with this error while using the
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
Writing my first C# application...never touched the language before and not much of a
I am in the process of writing a jQuery plugin for 3D text and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.