Skip to content Skip to sidebar Skip to footer

Android Webview - Detect Whether A Js Function Is Defined

I'm writing an HTML/JS application that runs under a WebView on Android. Under certain circumstances the page containing the application may not be loaded, or another page might in

Solution 1:

@JavascriptInterfacepublicvoidonLoaded(String result) {
    if (result.equals("function")) {
        // defined
    } else {
       // not defined
    }
}

privatevoidcheckJSFunction() {
    loadUrl("javascript:yourJSInterfaceName.onLoaded(typeof yourFunctionName)");
}

update: this code will check the JS function define by "typeof" and return its result to java through javascript interface "onLoaded".

Solution 2:

I think you can do it, Please look at PhoneGap project, you will find your answer.

PhoneGap is an awesome free framework for mobile platform.

Post a Comment for "Android Webview - Detect Whether A Js Function Is Defined"