zvzej zvzej - 6 days ago 5
Android Question

Android eclipse webview pop up not displaying

So I have a web app where I use a pop up window to display a message if something is not working or just to confirm something. I have made a simple android app on eclipse to use my web app through a web view, the problem I'm facing is that it seem that the web view inside the app does not support pop up windows.... Am I right or is there a way around to display pop up windows inside my app? here is the code I'm using for my web view. thanks for helping in advance.

wvp = (WebView) findViewById(R.id.webView1);
wvp.getSettings().setJavaScriptEnabled(true);
wvp.setWebViewClient(new WebViewClient());
wvp.setInitialScale(1);
wvp.getSettings().setBuiltInZoomControls(true);
wvp.getSettings().setDisplayZoomControls(false);
wvp.getSettings().setUseWideViewPort(true);


So if you have my same problem here is the solution thanks to ksasq

wvp = (WebView) findViewById(R.id.webView1);
wvp.getSettings().setJavaScriptEnabled(true);
wvp.setWebViewClient(new WebViewClient());
wvp.setWebChromeClient(new WebChromeClient());
wvp.setInitialScale(1);
wvp.getSettings().setBuiltInZoomControls(true);
wvp.getSettings().setDisplayZoomControls(false);
wvp.getSettings().setUseWideViewPort(true);
wvp.getSettings().setSupportMultipleWindows(true);
wvp.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);


this made the trick to be able to show that message pop up window I was after. enjoy!

Answer

There's a few things you need to do:

  1. Implement WebChromeClient.onCreateWindow [1]
  2. Toggle WebSettings.setSupportMultipleWindows[2] to true
  3. Depending on how the new window is created, you may need to enable WebSettings.setJavaScriptCanOpenWindowsAutomatically[3]

[1] http://developer.android.com/reference/android/webkit/WebChromeClient.html#onCreateWindow(android.webkit.WebView, boolean, boolean, android.os.Message)

[2] http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows(boolean)

[3] http://developer.android.com/reference/android/webkit/WebSettings.html#setJavaScriptCanOpenWindowsAutomatically(boolean)

Comments