Currently, I am working with Android version 5.0 and the latest update of the WebView component. My goal is to embed a remote website into a WebView without making any modifications to the source code of this website.
Here is the code snippet that I have implemented:
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains(URL_SERVLET)) {
//Do nothing
Log.d("DEBUG", "load IMAGE");
//view.stopLoading();
} else {
Log.d("DEBUG", "load URL into WebView");
view.loadUrl(url);
}
return true;
}
// Called when all page resources loaded
public void onPageFinished(WebView view, String url) {
webView.setVisibility(View.VISIBLE);
splashscreenLayout.setVisibility(View.GONE);
}
});
The issue arises when I encounter a button on the website's side that triggers another URL to open in a popup using JavaScript. When I click on this button within the Android WebView, the new URL replaces the current one displayed in the WebView. However, my intention is to prevent any action when clicking on this button.
The current implementation successfully prevents loading the additional URL, but it leads to the WebView displaying a blank white screen.
I have attempted calling stopLoading() without success in resolving this problem. Additionally, reloading the WebView via webview.reload() isn't feasible since the remote website generates HTML pages dynamically upon requests.
Efforts to save and restore the state of the WebView have also proved ineffective.
Is there a method to block the transition to a new URL and maintain the WebView's display of the initial content without triggering a reload?