How to get url from html a tag custom attributes in android?

1.1k views Asked by At
<a href="url_href" data-href="WANTED_URL">Click me</a>

In android webview is there any way to get url specified in custom attributes?

In my problem I need to get url present in data-href(i.e WANTED_URL) attributes when the user click on Click me link

Whenever user clicks on Click me link android provides url present in href attributes.Is there any way to get url present in custom attributes?

1

There are 1 answers

0
Mikhail Naganov On

WebView doesn't provide you with any information about the HTML elements you have clicked.

If you own the page you are showing in WebView, then one possible way to achieve your goal would be to encode WANTED_URL inside url_href, then parse it inside WebViewClient.shouldInterceptRequest (http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView,%20java.lang.String)).