I have a app which goes front and back with android and js coding. Here there is a fragments which loads a html file with js file when a button is clicked using web view. There is a button in the html page.When that button is clicked , its relative js function will be clicked. Now i wanted to call the same function on pressing of back button . How to do it?
Asked
Active
Viewed 485 times
1 Answers
0
Assuming your Javascript function is myFunction()
, you have to override onBackButton()
in your Activity
:
@Override
public void onBackPressed() {
myWebView.loadUrl("javascript:myFunction()");
}

Alberto Malagoli
- 1,173
- 10
- 14
-
i know that, but the html page was loaded in different fragment , but i have to load function in activity so for this myWebView - how to give the reference. – MBSGS Dec 18 '14 at 09:06
-
1take a look at [How to access Fragment's child views inside fragment's parent Activity?](http://stackoverflow.com/questions/24188050/how-to-access-fragments-child-views-inside-fragments-parent-activity) – Alberto Malagoli Dec 18 '14 at 09:23