Skip to content Skip to sidebar Skip to footer

Android Clicking A Button Inside A Webview

I'm trying to implement a button inside a webview, I'm using the following code : package com.example.tests; import android.os.Bundle; import android.annotation.SuppressLint; impo

Solution 1:

Change

<inputtype="submit" name="submit"id="submit_id" onclick="btnLogin.performClick();" />

to

<inputtype="submit" name="submit"id="submit_id" onclick="login.performClick();" />

Because your Interface name is login not btnLogin

For more info see this best post Android webview JavaScript Interface

Solution 2:

A tip: You can override opened links (<a href=) with the WebView:

myWebView.setWebViewClient(newMyWebViewClient());
publicclassMyWebViewClientextendsWebViewClient {

 @OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
        if ( url.equals("http://www.google.com") ){
            Log.d("debugging","we can do something here");
        }

        returntrue;
    }
}

Solution 3:

Solution 4:

you can add your javascript.js file in the assest folder do your coding whatever you want.

Inside the html you can add onclick="callFunction(); to any the tag. and you are done...

Post a Comment for "Android Clicking A Button Inside A Webview"