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");
2
  • use onclick="GreenClicked()" Commented Aug 21, 2014 at 7:28
  • changed it.still not working Commented Aug 21, 2014 at 7:31

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.