I have web application which works perfectly on desktop browser(Chrome), tablet browser(Chrome 48.0.256495). Web application has animation which uses jQuery. I am trying to show this app in WebView (Android 4.4.4). But animation which uses jQuery not working. I debuged webview using Desktop Chrome app and found this error:
Uncaught SyntaxError: Unexpected token ,
Error is showing this line:
cashier,
inside this piece of code
sellMiddle.find('#sell-users-wrapper').append(_users({
cashier,
customer,
assistants
}));
I have few questions about this issue:
1. What is causing this behaviour? Is this cause of relatively old JavaScript which is on Android 4.4.4? 2. If yes, can I update JavaScript which is used in WebView? How to identify JavaScript version? 3. If no, can I set new jQuery(using library or other tool) into WebView?
My code which includes WebView:
public class MainActivity extends AppCompatActivity {
private WebView mWebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
mWebview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
mWebview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
if (Build.VERSION.SDK_INT >= 19) {
mWebview.setWebContentsDebuggingEnabled(true);
mWebview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
mWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
if (savedInstanceState == null) {
mWebview.loadUrl("i://have.taken.url.for.security.purposes");
}
setContentView(mWebview);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mWebview.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mWebview.restoreState(savedInstanceState);
}
}