Friday, 15 January 2021

Window.beforeunload event is triggered in WebView in Android native app regardless of shouldOverrideUrlLoading return value

In Android-WebView, I am trying to open the selected/touched link in external app by overriding shouldOverrideUrlLoading.

Window beforeunload event is triggered, regardless of return value of shouldOverrideUrlLoading.

My site according to current implementation is considering ("beforeunload event") as user navigating away from the page and marking the user as inactive, which is not correct.

Want to understand the behaviour of WebView, so that I can handle correctly.

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) 
{
  if (request.getUrl().getHost().contains("mysite.com")) 
  {
     // same site load in WebView itself.
     return false;
  }

 Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
 startActivity(intent);
 return true;
}


from Window.beforeunload event is triggered in WebView in Android native app regardless of shouldOverrideUrlLoading return value

No comments:

Post a Comment