截图:file://的页面
无论如何要修改警报框标题吗?任何帮助将不胜感激。:)
实际上,您可以使用以下代码封装它:
final Context myApp=this;
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(myApp)
.setTitle("Simmon says...")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int wicht)
{
result.confirm();
}
}).setCancelable(false)
.create()
.show();
return true;
};
});
代码源在这里
升
有3种类型的 js 警报:
我添加了 onJsConfirm 的示例代码,
webViewLayout.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog dialog =new AlertDialog.Builder(view.getContext()).
setTitle("Confirm").
setIcon(ContextCompat.getDrawable(view.getContext(),R.drawable.image)).
setMessage(message).
setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
}).
setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FlashMessage("JS");
result.confirm();
}
})
.create();
dialog.show();
return true;
}
});
@Pointy 说由于浏览器的安全措施,这是不可能的。
是的,有可能,我做到了
webview.setWebChromeClient(new WebChromeClient() {
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(activity)
.setTitle("Calendário App...")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int wicht)
{
result.confirm();
}
}).setCancelable(false)
.create()
.show();
return true;
};
});