I am trying to allow a new window to be opened in a WebView when a button on a website is pressed. I have tried enabling both setJavaScriptCanOpenWindowsAutomatically
and setSupportMultipleWindows
, but still nothing happens when the button is pressed.
public class WebView extends AppCompatActivity {
android.webkit.WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
myWebView = (android.webkit.WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
webSettings.setAllowFileAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
myWebView.loadUrl("https://somewebsite.com/");
}
@Override
protected void onSaveInstanceState(Bundle outState ) {
super.onSaveInstanceState(outState);
myWebView.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
myWebView.restoreState(savedInstanceState);
}
}
I have read and tried the suggested answers in the following:
I think the reason the answer in the question linked here may not be working for my case because the linked question is talking about a popup within the same window, but the button I am clicking opens a new window entirely (which I cannot change).
Does anyone why know why setJavaScriptCanOpenWindowsAutomatically
and setSupportMultipleWindows
aren't doing the trick and how I can set up my webview so that it allows clicking a button that opens a new window?