I need to call a c++ function from the javascript. Please somebody hlp..
-
5Javascript running in the browser? Javascript running on the web server? Please be more specific.dthorpe– dthorpe2010-12-15 05:36:47 +00:00Commented Dec 15, 2010 at 5:36
-
4and perhaps also state what you're actually trying to do. The solution might not involve c++ (or javascript) at all.jrharshath– jrharshath2010-12-15 05:38:48 +00:00Commented Dec 15, 2010 at 5:38
5 Answers
If you are talking about a web browser, then running native code from Javascript is usually done by exposing the necessary functions through a web browser plugin. Different web browsers have different ways to write plugins; Firefox and Chrome use NPAPI whereas Internet Explorer uses ActiveX.
There is an open source project called Firebreath which makes it really easy to write cross-platform browser plugins which work on both NPAPI and ActiveX hosts.
Comments
Take a look at WebKit/Qt (assuming you are interested in writing a browser that exports additional features to the JavaScript - special hardware-related API and the likes)
1 Comment
You can invoke any c++ function after compiling it into dll using javascript by extending Activex Object
like
var myNativeObj= new ActiveXObject("foo.dll");
myNativeObj.someMethod();//Some Method is defined in class
but this is restricted to Internet Explorer browser alone.
2 Comments
You can write browser extension and use it from javascript code.
Comments
In IE, you can use ActiveX.
In Firefox, you can use js-ctypes: https://wiki.mozilla.org/Jsctypes/api
In Chrome, I'm not sure, V8 maybe have a support.