ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Android : Close box on WebView

by Little Bear @20 ก.ย. 63 18:12 ( IP : 14...63 ) | Tags : Android , Kotlin
fun evaluateJsFromNative(command: String,
    webView: WebView, function: (value : Boolean) -> Unit ) {
    webView.evaluateJavascript("(function() { return $command; })();") {
        s -> function(s.toBoolean())
    }
}
override fun onBackPressed() {
    var boxCheck = "document.getElementsByClassName('box-page')[0].tagName == 'DIV';"
    evaluateJsFromNative(boxCheck, myWebView) {
        if (it) {
            evaluateJsFromNative("$.colorbox.close()", myWebView){}
        } else {
            super.onBackPressed()
        }
    }
}

Relate topics