It is a bad idea to get Cordoba to load JavaScript into the page load. This should be handled by your local JavaScript. Try calling the display () function, as in the HTML page itself:
<script> function display() { alert("abc"); } window.onload = function() { display(); } </script>
If you need to call JavaScript from Cordoba at any subsequent moment, you can do it like this:
sendJavascript("display();");
To access this method from other classes, you need to access your main activity. An easy, but possibly unsafe method is to create a static variable in your main activity that will keep the activity itself. Example:
public class MyActivity extends DroidGap { public static MyActivity activity; public void onCreate(Bundle savedInstanceState) { activity = this; } }
Then from anywhere in your classes do:
MyActivity.activity.sendJavascript('display();');
source share