Change alert () header (Javascript on Android Webview)

Screenshot: Page in file: //

Can I change the title of the warning window? Any help would be appreciated. :)

+8
source share
4 answers

@Pointy says this is not possible due to browser security measures.

+1
source

Indeed, you can envelop it using the following code:

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; }; }); 

Source code here

GL

+11
source

There are 3 types of js alerts:

  • warning window - with the OK button to continue.
  • confirm the field - both with OK and with the cancel button.
  • prompt window - get the value from the user and then select OK / Cancel.

  • Use onJsAlert for alertBox .
  • Use onJsConfirm to confirm .
  • Use onJsPrompt for promptBox

I added sample code for 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.car5)). 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; } }); 
+1
source

Yes maybe i did it

  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; }; }); 
0
source

All Articles