Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView New Window URL

I've got an issue with Android WebView, I want to open a URL with target='_blank' in the same WebView, just as all other URLs are opening.

Also note that im overriding this method of WebViewClient 'shouldOverrideUrlLoading', for handling URL redirects (so that all URL redirects are opened in my WebView) but in case of URLs with target='_blank' this method doesn't get fired.

Kindly help! Thanks in advance.

like image 663
Saad Umair Avatar asked Jul 27 '11 10:07

Saad Umair


2 Answers

Try to add :

webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setSupportMultipleWindows(false);

And in shouldOverride :

view.loadUrl(url);
return true;
like image 189
ChristopheCVB Avatar answered Sep 30 '22 18:09

ChristopheCVB


WebSettings settings = webView.getSettings();

//Enable support multiple windows
settings.setSupportMultipleWindows(true);

webView.setWebChromeClient(new WebChromeClient() {
    @Override 
    public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)
    {
        //return true or false after performing the URL request
    }
 });
like image 32
ksivamuthu Avatar answered Sep 30 '22 17:09

ksivamuthu