1

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);
}

}

Joe Richard
  • 1,520
  • 7
  • 20
  • 31
  • you enable javascript in the webview settings? post yourwebview code – Tasos Mar 02 '16 at 10:44
  • i have added code where i declared webview set all its settings – Joe Richard Mar 02 '16 at 10:55
  • code looks ok -- try Crosswalk https://crosswalk-project.org/ as a test which is a replacement of webview as it uses Chromium -- http://stackoverflow.com/questions/28781803/embed-crosswalk-in-android-studio -- in gradle change the version number to the latest Stable -- https://crosswalk-project.org/documentation/downloads.php – Tasos Mar 02 '16 at 11:10
  • now loading org.xwalk:xwalk_core_library:14.43.343.17 – Joe Richard Mar 02 '16 at 12:01
  • 16.45.421.19 -- is the latest – Tasos Mar 02 '16 at 13:01
  • 1
    This may seem strange, but experimenting with WebView I found that the work is highly dependent on what kind of devices (phone or tablet) are used. Part of JS methods (for example - includes etc) does not work on the tablet, is also strongly depends on the API – Delphian Feb 03 '17 at 12:51

0 Answers0