Jason Zhao
Jason Zhao

Reputation: 1288

Can listen click content in Webview on Android

I used a webview to load up a webpage. Is there a way to listen click action to know what hyper link is clicking on webview? For example, if click hyper link 1 then switch to native code page 1, if click hyper link 2 then jump to native code page 2....

Upvotes: 0

Views: 1933

Answers (2)

Jordy Langen
Jordy Langen

Reputation: 3591

Have a look at this:

http://developer.android.com/guide/webapps/webview.html

You might find this usefull:

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.example.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }

Upvotes: 5

jennifer
jennifer

Reputation: 8261

Using JavaScript in WebView you can do this. pls refer the link below.

Android WebView WebChromeClient example tutorial

http://developer.android.com/guide/webapps/webview.html

Upvotes: 6

Related Questions