我遇到了以下問(wèn)題。網(wǎng)頁(yè)中有一部分: document.getElementById('continueButton').addEventListener('click', function () { window.parent.postMessage('PAYLANDS-ERROR', '*'); if (window.parent.HTMLOUT) { window.parent.HTMLOUT.paylandsFail(); } });這是我的界面,其中包含帶有注釋 @JavascriptInterface 的方法:interface IAddCard3dsJavaScript { @JavascriptInterface fun paylandsSuccess() @JavascriptInterface fun paylandsFail() companion object { const val INTERFACE_NAME = "HTMLOUT" }}有一個(gè)類實(shí)現(xiàn)了這個(gè)接口:class AddCard3dsJavaScript(private val presenter: IAddCard3dsCallback) : IAddCard3dsJavaScript { override fun paylandsSuccess() { presenter.onPaylands3dsSuccess() } override fun paylandsFail() { presenter.onPaylands3dsFailed() }}但是當(dāng)我運(yùn)行該應(yīng)用程序時(shí),我在控制臺(tái)中看到了這一行Uncaught TypeError: window.parent.HTMLOUT.paylandsFail is not a function:我嘗試將接口名稱更改為window.parent.HTMLOUT而不是HTMLOUT,在這種情況下,我沒(méi)有收到錯(cuò)誤,但paylandsFail 方法體沒(méi)有執(zhí)行。那么,問(wèn)題是什么以及如何解決呢?UPD這是我如何將此接口添加到 webview 的方法:@SuppressLint("JavascriptInterface") override fun loadUrlFor3ds(url: String) { addCardWebView?.apply { addJavascriptInterface(AddCard3dsJavaScript(getController()), IAddCard3dsJavaScript.INTERFACE_NAME) loadUrl(url) } }
JS 函數(shù)無(wú)法識(shí)別 JavaScript 接口方法
天涯盡頭無(wú)女友
2023-09-21 14:01:48