Alex Rivera | Logout

Prevent WebView from Opening the Browser

Asked 2012-11-10T11:12:47.823
17

I'm already active JavaScript for a given WebView, and opens new link inside the WebView, not in the Browser. This Is Main Activity

    package com.Afrogfx.pronouns;

    import android.os.Bundle;
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.view.Menu;
    import android.webkit.WebView;

    @SuppressLint("SetJavaScriptEnabled")
    public class MainActivityPronouns extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_activity_pronouns);

    WebView wvHtml = (WebView) findViewById(R.id.webview);
    wvHtml.getSettings().setBuiltInZoomControls(true);
    wvHtml.getSettings().setJavaScriptEnabled(true);
    wvHtml.loadUrl("http://afrogfx.com/appcatcategories.php?catid=13&parentid=11");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main_activity_pronouns, menu);
    return true;
    }
    }

how can i handel my code to open all link in site inside the WebView (App) , not in the Browser & ( don't show to user Open in browser).

Edit
Report

1 Answer

32

For that just create the subclass that is extending webclient and use the method of that class onPageFinished(WebView c,String url) and
public boolean shouldOverrideUrlLoading(final WebView view, final String url)

here is the code-

 myWebView.setWebViewClient(new WebViewClient()       
        {
             @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) 
            {
                //view.loadUrl(url);
                System.out.println("hello");
                return false;
            }
        });
        myWebView.loadUrl(url);
answered 2012-11-10T11:25:12.523

Your Answer