2

I know the question is highly general, and seem to be irrelevant. I myself know that this type of questions should not be asked here. But after researching for long, posting to the blogs of many Phonegap masters, I got no replies from them, I have now came to StackOverflow. So much so, that there are no documentation for this particular method anywhere on the Internet, neither in PhoneGap Docs, nor in Cordova Docs.

My question is very simple. I want to know, how to use the sendJavascript() in the DroidGap class or the Plugin class to call a function in Javascript.

I found this tutorial, but it is very obsolete and doesn't work with Phonegap 3.0. It would be very nice if someone suggest some modification in the tutorial, or some new approach.

I don't need the code, just tell me how to do it. I just need a skeleton

I posted a similar question, actually it is the original problem, to which I am looking the solution for.

Please suggest me something on this. I'll be very glad.


Edit 1: On searching to the deepest of Google, I found this first documentation of this creepy method. Here is the link

Community
  • 1
  • 1
Anas Azeem
  • 2,820
  • 3
  • 24
  • 37

1 Answers1

1

The sendJavascript function is defined in CordovaWebView.

Each Cordova plugin has a webView property that should give you easy access to call the javascript function.

Vlad Stirbu
  • 1,732
  • 2
  • 16
  • 27
  • Thanks @Vlad for answering, but the question is when I write `sendJavacript()` and call some method of Javascript, where that method would reside (I mean in which JS file, if I am having many of them). I know the language I used is a bit vague, but please bear with me this time. Please ask if you wanna know anything else. – Anas Azeem Nov 13 '13 at 06:19
  • You should call the function as if you were in the global execution context – Vlad Stirbu Nov 13 '13 at 06:40
  • Sorry Vlad, I know about Android and Java, but I am very new to Web and Javascript. Please Please can you give me a detailed answer. As I said in the question, _I just need a skeleton not the full code_. Please help me. – Anas Azeem Nov 13 '13 at 06:43
  • Is as simple as this ```sendJavascript("alert('from native side');")```, just pass the javascript string that you want to execute – Vlad Stirbu Nov 13 '13 at 15:15
  • Thanks Vlad, I tried it, and its running. But then I need to call a Javascript function (say `callFromNative()`). So, where do I need to put that function in Javasrcript, I mean in which file, since there are so many Javascript files in the project. I know that feels odd, but please, I am waiting for to long. – Anas Azeem Nov 14 '13 at 05:48
  • 1
    It does not matter in which file you put it as long as you include the script in your index.html. – Vlad Stirbu Nov 15 '13 at 18:41
  • Thanks for the reply, I'll now give it another shot. Fingers Crossed – Anas Azeem Nov 16 '13 at 04:26