2

I'm trying to handled onclick of html in android.refered enter link description here but its not detecting.

<script language="javascript">

   function GreenClicked()
   {
      valid.performClick();
      document.getElementById("Green").value = "J'accepte";
   }
</script>

html tag inside body-

 <div  id="Green" onclick="GreenClicked()">Green<span></span></div>

java code -

mGreenPassenger= new Button(getActivity());
        mGreenPassenger.setOnClickListener(this);

        WebSettings ws = mWebView.getSettings();
        ws.setJavaScriptEnabled(true);
        // Add the interface to record javascript events
        mWebView.addJavascriptInterface(mGreenPassenger, "Green");
Community
  • 1
  • 1
yuva ツ
  • 3,707
  • 9
  • 50
  • 78

1 Answers1

4

The pitfalls of copying code from StackOverflow is that you might not understand it fully.

function GreenClicked()
{
    Green.performClick(); // Needs to be your JS Interface name
    document.getElementById("Green").value = "J'accepte";
}

The Android docs on this are great. Use them. You'll have more of an understanding of what's going on in your own code.

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176