eclipse - Find html class inside Android WebView -


i trying create simple app on phone. job load webpage, , copy specific class inside page (in case address) simple example;

on random page, found line in source;

<div class='address'>a adress should copy on start</div><div class='phone'> 0000000000 (dont need anyway)</div> 

as can see there 2 classes, address , phone copy contents inside address class a adress should copy on start

does know if possible ? have looked up, there not info avaiable, android...

thank time.

regards

you can in 2 steps

step 1: inject javascript function on webpage

step 2: call java method javascript using javascriptinterface

below code goes in activity's oncreate method

final webview webview = (webview)findviewbyid(r.id.browser);   webview.getsettings().setjavascriptenabled(true);    javascriptinterface jsinterface = new javascriptinterface(this); webview.getsettings().setjavascriptenabled(true); webview.addjavascriptinterface(jsinterface, "jsinterface");  webview.setwebviewclient(new webviewclient() {           @override           public void onpagefinished(webview view, string url)           {               webview.loadurl("javascript:(function() { " +                       "var content = document.getelementsbyclassname('address')[0].innerhtml; " + "window.jsinterface.printaddress(content);" +                     "})()");           }       });    webview.loadurl("http://your-web-url.com/");   

where javascriptinterface can this

public class javascriptinterface {     private activity activity;      public javascriptinterface(activity activiy) {         this.activity = activiy;     }      public void printaddress(string address){         toast.maketext(activity, "address: "+address, toast.length_long).show();     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -