开发者

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(开发者_C百科'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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜