vijay
vijay

Reputation: 123

android webview javascript not working

I am using simple webview.Where i have given link to login page of my web application. The webview work fine until i try custom webviewClient. By adding webviewClient it stops processing of javascript.I am able to see only html part.

 webView = (WebView) findViewById(R.id.webView1);
 webView.setWebViewClient(new MyBrowser());
 WebSettings webSettings = webView.getSettings();
 webSettings.setJavaScriptEnabled(true);
 webView.loadUrl("my web application login page with jscript"); 


private class MyBrowser extends WebViewClient {
   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
   }
}

I am able to login successfully.There is javascript in login page,so i think it works.But after logging in it redirects to home page where onpage load javascript will append some data to html table.The data which is appended by jscript is visible in other browser,but webview not showing that data.

Upvotes: 2

Views: 1791

Answers (1)

Tharif
Tharif

Reputation: 13971

Try the below that enables javascript

  public class WebViewDemo extends Activity {
   private static final String URL_TO_LOAD = "http://google.com";
   private static final String LOCAL_RESOURCE = "file:///android_asset/html/HelloWorld.html";
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.browser_demo);
      WebView view= (WebView) findViewById(R.id.browser1);
      loadResource(view, LOCAL_RESOURCE);
   }
   private void loadResource(WebView view, String resource) {      wv.loadUrl(resource);
      view.getSettings().setJavaScriptEnabled(true);
      view.setWebChromeClient(new CustomChromeclient());
      view.setWebViewClient(new CustomWebViewclient(this));
      view.addJavascriptInterface(new JavaScriptInterface(view), "JSI");
   }  //

Upvotes: 2

Related Questions