Untitled

From Smelly Monkey, 13 Years ago, written in Java, viewed 3 times.
URL https://paste.blessuren.de/view/bcf8c1db Embed
Download Paste or View Raw
  1. final Context myApp = this;
  2.  
  3. /* An instance of this class will be registered as a JavaScript interface */
  4. class MyJavaScriptInterface
  5. {
  6.     @SuppressWarnings("unused")
  7.     public void processHTML(String html)
  8.     {
  9.         // process the html as needed by the app
  10.     }
  11. }
  12.  
  13. final WebView browser = (WebView)findViewById(R.id.browser);
  14. /* JavaScript must be enabled if you want it to work, obviously */
  15. browser.getSettings().setJavaScriptEnabled(true);
  16.  
  17. /* Register a new JavaScript interface called HTMLOUT */
  18. browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
  19.  
  20. /* WebViewClient must be set BEFORE calling loadUrl! */
  21. browser.setWebViewClient(new WebViewClient() {
  22.     @Override
  23.     public void onPageFinished(WebView view, String url)
  24.     {
  25.         /* This call inject JavaScript into the page which just finished loading. */
  26.         browser.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
  27.     }
  28. });
  29.  
  30. /* load a web page */
  31. browser.loadUrl("http://lexandera.com/files/jsexamples/gethtml.html");

Reply to "Untitled"

Here you can reply to the paste above