Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid html code from webview
    primarykey
    data
    text
    <p>hello i'm using this example <a href="http://lexandera.com/2009/01/extracting-html-from-a-webview/" rel="nofollow">http://lexandera.com/2009/01/extracting-html-from-a-webview/</a> to get the HTML from a webview. But i need to use it in my superclass and i dont know how to do this. I just can see the html on a AlertDialog but i cant use it. How can I return it to my main class as String?</p> <pre><code>final Context myApp = this; /* An instance of this class will be registered as a JavaScript interface */ class MyJavaScriptInterface { @SuppressWarnings("unused") public void showHTML(String html) { new AlertDialog.Builder(myApp) .setTitle("HTML") .setMessage(html) .setPositiveButton(android.R.string.ok, null) .setCancelable(false) .create() .show(); } } final WebView browser = (WebView)findViewById(R.id.browser); /* JavaScript must be enabled if you want it to work, obviously */ browser.getSettings().setJavaScriptEnabled(true); /* Register a new JavaScript interface called HTMLOUT */ browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT"); /* WebViewClient must be set BEFORE calling loadUrl! */ browser.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { /* This call inject JavaScript into the page which just finished loading. */ browser.loadUrl("javascript:window.HTMLOUT.showHTML('&lt;head&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/head&gt;');"); } }); /* load a web page */ browser.loadUrl("http://lexandera.com/files/jsexamples/gethtml.html"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload