//允許使用 javascript
webView.Settings.JavaScriptEnabled = true;
webView.SetWebChromeClient(new CustChromeWebViewClient(this));
二、Override alert confirm 事件:
private class CustChromeWebViewClient : WebChromeClient
{
private Context _context;
public CustChromeWebViewClient(Context father)
{
_context = father;
}
public override bool OnJsAlert(WebView view, string url, string message, JsResult result)
{
new AlertDialog.Builder(_context).SetTitle("提示訊息").SetMessage(message).SetPositiveButton("確定", delegate
{
result.Confirm();
}).Create().Show();
return true;
}
public override bool OnJsConfirm(WebView view, string url, string message, JsResult result)
{
new AlertDialog.Builder(_context).SetTitle("提示訊息").SetMessage(message).SetPositiveButton("確定", delegate
{
result.Confirm();
}).SetNegativeButton("取消",delegate {
result.Cancel();
})
.Create().Show();
return true;
}
}
三、 完成以上項目後,就可以測試WebView 上響應 Alert Confirm 事件