共用方式為


WebChromeClient.OnJsPrompt Method

Definition

Notify the host application that the web page wants to display a JavaScript prompt() dialog.

[Android.Runtime.Register("onJsPrompt", "(Landroid/webkit/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/webkit/JsPromptResult;)Z", "GetOnJsPrompt_Landroid_webkit_WebView_Ljava_lang_String_Ljava_lang_String_Ljava_lang_String_Landroid_webkit_JsPromptResult_Handler")]
public virtual bool OnJsPrompt (Android.Webkit.WebView? view, string? url, string? message, string? defaultValue, Android.Webkit.JsPromptResult? result);
[<Android.Runtime.Register("onJsPrompt", "(Landroid/webkit/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/webkit/JsPromptResult;)Z", "GetOnJsPrompt_Landroid_webkit_WebView_Ljava_lang_String_Ljava_lang_String_Ljava_lang_String_Landroid_webkit_JsPromptResult_Handler")>]
abstract member OnJsPrompt : Android.Webkit.WebView * string * string * string * Android.Webkit.JsPromptResult -> bool
override this.OnJsPrompt : Android.Webkit.WebView * string * string * string * Android.Webkit.JsPromptResult -> bool

Parameters

view
WebView

The WebView that initiated the callback.

url
String

The url of the page requesting the dialog.

message
String

Message to be displayed in the window.

defaultValue
String

The default value displayed in the prompt dialog.

result
JsPromptResult

A JsPromptResult used to send the user's reponse to javascript.

Returns

boolean true if the request is handled or ignored. false if WebView needs to show the default dialog.

Attributes

Remarks

Notify the host application that the web page wants to display a JavaScript prompt() dialog.

The default behavior if this method returns false or is not overridden is to show a dialog containing the message and suspend JavaScript execution until the dialog is dismissed. Once the dialog is dismissed, JavaScript prompt() will return the string that the user typed in, or null if the user presses the 'cancel' button.

To show a custom dialog, the app should return true from this method, in which case the default dialog will not be shown and JavaScript execution will be suspended. The app should call JsPromptResult.confirm(result) when the custom dialog is dismissed.

To suppress the dialog and allow JavaScript execution to continue, call JsPromptResult.confirm(result) immediately and then return true.

Note that if the WebChromeClient is set to be null, or if WebChromeClient is not set at all, the default dialog will be suppressed and null will be returned to the JavaScript code immediately.

Note that the default dialog does not inherit the android.view.Display#FLAG_SECURE flag from the parent window.

Java documentation for android.webkit.WebChromeClient.onJsPrompt(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String, android.webkit.JsPromptResult).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to