简体   繁体   中英

Android webview limited loading

i hope someoune can help me with this problem that gived me headeakes.

package org.example.browserview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class BrowserView extends Activity {

   private WebView webView;

   @Override
   public void onCreate(Bundle savedInstanceState) {

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

      webView = (WebView) findViewById(R.id.web_view);

      webView.getSettings().setJavaScriptEnabled(true);
      webView.loadUrl("http://m.test.com");  
   }  
}

It works but the problem i have is that i dont want to load all the page into my webkit, i want to load the page without the header of the html. (so i need to hide the header somehow)

The html header id i've set it to "header" and i used jquery in the html page. So all i have to do and i dont know is how to make a javascript command $('header').hide(); or document.getElementById('header').hide(); before i insert the page into android application.

So in this way i will get the page into android application without the header.

I guess you can call JavaScript with loadUrl("javascript:...;") after loadUrl("http://..."):

webView.loadUrl("javascript:$('header').hide();");

or

webView.loadUrl("javascript:document.getElementById('header').style.display='none';");

See also: http://lexandera.com/2009/01/injecting-javascript-into-a-webview/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM