Well, this is not ideal, but you can track the history of navigation manually using an array (or just an integer that needs to be increased and decreased), and click on the current url every time it changes, and pull the last URL out of it when you press the back button, and if the array is empty (or an integer is 0), you call super.onBackPressed() .
To execute the code when the URL changes, you can override the boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) WebViewClient ( link to the documentation ).
Thus, javascript of web pages cannot interfere with how you handle the back button.
nonzaprej
source share