Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think the method signature is should be next to override your desired action.

public boolean shouldOverrideUrlLoading(WebView view, String url) {

Other possible updates might be

  1. to ensure you do NOT have multi window settings mWebView.getSettings().setSupportMultipleWindows(true);

  2. And sometimes you HAVE to set mixed content property webView.getSetting().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...