Ошибка JavaScript не может найти функцию
когда кликаю по кнопке вылетает эта ошибка Uncaught typeerror: android interface.onbuttonclick is not a function (line:7)
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
WebView webView = FindViewById<WebView>( Resource.Id .webView);
consoleOutput = FindViewById<TextView>( Resource.Id .consoleOutput);
WebSettings webSettings = webView.Settings;
webSettings.JavaScriptEnabled = true;
webView.AddJavascriptInterface(new WebViewJavaScriptInterface(this), "AndroidInterface");
webView.SetWebViewClient(new CustomWebViewClient(consoleOutput));
webView.SetWebChromeClient(new CustomWebChromeClient(consoleOutput));
webView.LoadUrl("адрес страницы");
}
<!DOCTYPE html>
<html>
<head>
<title>WebView Example</title>
<script type="text/javascript">
window.onload = function () {
if (typeof AndroidInterface !== "undefined") {
console.log("AndroidInterface доступен");
} else {
console.log("AndroidInterface не доступен");
}
};
function buttonClick() {
try {
AndroidInterface.onButtonClick(); // Вызов функции
console.log("Кнопка нажата!");
} catch (error) {
console.error("Ошибка при вызове функции:", error);
}
}
</script>
</head>
<body>
<button onclick="buttonClick()">Нажми меня</button>
</body>
</html>
Попробуй открыть в другом браузере