0
protected void onCreate(Bundle savedInstanceState) {
    String javaScript = "javascript:(function(){var%20content=document.getElementsByClassName('entry-content')[0].innerHTML;var%20content2=content.replace(/<p>/,'');var%20endpos=content2.search(/<div%20id/);})()";



    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_neugkeiten_rss_item);

    Bundle bundle = getIntent().getExtras();
    String item_link = bundle.getString("link");
    String item_title = bundle.getString("title");

    TextView textViewTitle = (TextView) findViewById(R.id.textViewRssItemTitle);
    textViewTitle.setText(item_title);

    WebView webViewContent = (WebView) findViewById(R.id.webViewNewsContent);
    webViewContent.getSettings().setJavaScriptEnabled(true);
    webViewContent.loadUrl("file:///android_asset/Resources/rsscontent.html");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home, menu);
    return true;
}

public void onbuttonclick (View view) {
    WebView webViewContent = (WebView) findViewById(R.id.webViewNewsContent);
    webViewContent.getSettings().setJavaScriptEnabled(true);
    webViewContent.loadUrl("javascript:(function() {var%20content=document.getElementsByClassName('entry-content')[0].innerHTML;var%20content2=content.replace(/<p>/,'');var%20endpos=content2.search(/<div%20id/);var%20content3=content2.slice(0,endpos);var%20content4=content3.replace(/%20%20%20%20/,'');document.body.innerHTML=content4;document.body.style.backgroundColor='#e9e9e9';})()");
}

Hi Guys,

I have a problem: I want to load a webpage into my web view and then run a javascript onto it that removes all irrelevant content and redefines the background color. My javascript does work on pc but not in the android browser or in the webview. Do you know whats wrong in the code?

Api-Level 11 Target 17

It would be also great if someone of you knows a good tutorial on how to download html files

1 Answers1

0

Did you tried this :

1- add this line to your onCreate function

webViewContent.setWebViewClient(new myWebClient());

then 2- add this class into your class

public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageFinished (WebView view, String url) {
            view.loadUrl("javascript:(function(){var%20content=document.getElementsByClassName('entry-content')[0].innerHTML;var%20content2=content.replace(/<p>/,'');var%20endpos=content2.search(/<div%20id/);})()");
        }         
    }
Mohamed Habib
  • 883
  • 1
  • 8
  • 18
  • doesn't work. But thanks for your help. Can you tell me a good tutorial on how to download html files using an AsyncTask?? – moritzbruder Apr 29 '13 at 12:36
  • did you tried to make this function in your html and just call it from activity like view.loadUrl("javascript:functionName();"); – Mohamed Habib Apr 29 '13 at 12:38
  • The html is always changing and for me ist not possible to change the html because im not the author of it. But if you know how to load a webpage over a javascript and then continue the script i could write an html file that will do this and put that one into my webview. – moritzbruder Apr 30 '13 at 14:26