In Android Browser link does not always execute onClick causing focus instead

后端 未结 5 2227
梦如初夏
梦如初夏 2021-02-09 07:51

I am trying to program a very standard JS behavior for a link using an HREF onClick handler, and I am facing a strange problem caused by what I believe to be focus/touch mode be

5条回答
  •  醉酒成梦
    2021-02-09 08:39

    Recently I came across exactly the same problem. I was using the onclick on a button. Sometimes it did not execute the javascript at all. The thing that worked for me was that enable the javascript before loading a url in the webview

        // Enable javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    
        // To bind javascript code to android
        mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
    
        mWebView.loadUrl(url);
    

提交回复
热议问题