0

I've got an Android Phonegap app that takes a website and injects a few new libraries and stylesheets (zeptojs angularjs etc.)

In my specific case I cannot simply re-write the code to JavaScript on the page (as I'm not the one in charge of the page's scripts), instead I'd like to use the Java function sendJavascript(), and run it from a Java timer object.

But no matter how I call sendJavascript it never seems to do anything.

eg:

myActivity.this.sendJavascript("javascript: alert(1)");

But alert(1) never actually fires

Shane Gadsby
  • 1,260
  • 1
  • 13
  • 19

1 Answers1

0
  1. To call the java function from javascript you have to write a phone gap plugin. Then in the change page handler you call the javascript function from the plugin.

  2. Can you give more details on what the alert is all about? Does it relate to the java function that you want to call previously, or is something that you want to notify from the native side?

Vlad Stirbu
  • 1,732
  • 2
  • 16
  • 27
  • I need the reverse, to call a JavaScript function from Java, using the `sendJavascript` function that is available from Phonegap/Cordova. I'll edit my question to clear that up. `alert(1)` is just the test javascript code. It's a native function to javascript and often used for examples as it is in this case (see: http://www.w3schools.com/jsref/met_win_alert.asp) – Shane Gadsby Mar 25 '13 at 00:43
  • In that case, this might help: http://stackoverflow.com/questions/12514039/calling-javascript-function-from-the-android-activity – Vlad Stirbu Mar 25 '13 at 07:23