Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable javascript into webView

In android if I use javascript into webView it gives Force Close. Is there any possibilities for using java script into webView. please help...

01-10 10:08:51.513: W/dalvikvm(5994): JNI WARNING: jarray 0x407447a8 points to non-array object (Ljava/lang/String;) 01-10 10:08:51.513: I/dalvikvm(5994): "WebViewCoreThread" prio=5 tid=9 NATIVE 01-10 10:08:51.513: I/dalvikvm(5994):   | group="main" sCount=0 dsCount=0 obj=0x40567400 self=0x1f9e58 01-10 10:08:51.513: I/dalvikvm(5994):   | sysTid=6010 nice=0 sched=0/0 cgrp=default handle=2269896 01-10 10:08:51.513: I/dalvikvm(5994):   | schedstat=( 44479977019 41285891893 14352 ) 01-10 10:08:51.513: I/dalvikvm(5994):   at android.webkit.WebViewCore.nativeTouchUp(Native Method) 01-10 10:08:51.513: I/dalvikvm(5994):   at android.webkit.WebViewCore.nativeTouchUp(Native Method) 01-10 10:08:51.543: I/dalvikvm(5994):   at android.webkit.WebViewCore.access$3300(WebViewCore.java:53) 01-10 10:08:51.543: I/dalvikvm(5994):   at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1158) 01-10 10:08:51.543: I/dalvikvm(5994):   at android.os.Handler.dispatchMessage(Handler.java:99) 01-10 10:08:51.543: I/dalvikvm(5994):   at android.os.Looper.loop(Looper.java:123) 01-10 10:08:51.543: I/dalvikvm(5994):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629) 01-10 10:08:51.557: I/dalvikvm(5994):   at java.lang.Thread.run(Thread.java:1019) 01-10 10:08:51.557: E/dalvikvm(5994): VM aborting 
like image 486
Dhanesh Avatar asked Jan 13 '12 04:01

Dhanesh


People also ask

How do I enable JavaScript on WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.

Can WebView run JavaScript?

WebView allows you to bind JavaScript code to Android code through an interface. To do this, we must use the addJavaScriptInterface() method, which is passed the class that provides the interface for JS, and the name that will be used to display the instance in JS (for example, “AndroidFunction“).

What is JavaScript WebView?

WebView is a special component in Android which serves as kind of built-in browser inside Android applications. If you want to execute HTML, CSS or JavaScript code in your Android app, or you need to allow users visit a URL without leaving your application, WebView is the way to go.

How do I enable WebView?

To do so, launch the Play store, scroll the apps on your home and locate Android System WebView. Click on Open, and now you see the disabled button, click on Enable.


2 Answers

JavaScript is disabled in a WebView by default.

WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); 
like image 128
Vamsi Krishna B Avatar answered Sep 23 '22 10:09

Vamsi Krishna B


 WebView webView = (WebView) findViewById(R.id.webview);         webView.getSettings().setJavaScriptEnabled(true);         webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 
like image 23
Mina Fawzy Avatar answered Sep 26 '22 10:09

Mina Fawzy