开发者

How to get the webview's content which was clicked on the webview

I want to add the bookmark functio开发者_开发百科n to my app, when I clicked on the webview which display the HTML files (The file's main part is string), I want to capture the first line of the content which display on the screen. Anyone knows the answer?

Thanks very much in advance.

-Shawn


you can identify the some content of the page as It contains img tag or not Use this API of webView click here

 WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
 int i=hr.getType() ;

and use the int values of this class for the content

Hope it help


If there is a link into the WebView and you want to do a specific action when the user click on this link you must catch the link click using the following code:

Somewhere in your activity code (commonly in the onCreate method):

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.news_details);
    ...
    mWebView.setWebViewClient(new MyWebViewClient());
    ...
}

And the WebViewClient class:

class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (DEBUG) {
            Log.d(TAG, "shouldOverrideUrlLoading url= " + url);
        }
        if ( the url is like you want) {
            // TODO: add the code to do what you need to do with the url
            // the webview should not do anything with this link.
            return true;
        } else {
            // let the webview normally handle the link
            return false;
        }
    }
}

If what you want to do is get the actual displayed content of the WebView, there is no API to do that.

Have a look on those post:

Is it possible to get the HTML code from WebView

Retrieve webview content

Both redirect on this website:

http://lexandera.com/2009/01/extracting-html-from-a-webview/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜