Sdílet prostřednictvím


WebView.EvaluateJavascript(String, IValueCallback) Method

Definition

Asynchronously evaluates JavaScript in the context of the currently displayed page.

[Android.Runtime.Register("evaluateJavascript", "(Ljava/lang/String;Landroid/webkit/ValueCallback;)V", "GetEvaluateJavascript_Ljava_lang_String_Landroid_webkit_ValueCallback_Handler")]
public virtual void EvaluateJavascript (string script, Android.Webkit.IValueCallback? resultCallback);
[<Android.Runtime.Register("evaluateJavascript", "(Ljava/lang/String;Landroid/webkit/ValueCallback;)V", "GetEvaluateJavascript_Ljava_lang_String_Landroid_webkit_ValueCallback_Handler")>]
abstract member EvaluateJavascript : string * Android.Webkit.IValueCallback -> unit
override this.EvaluateJavascript : string * Android.Webkit.IValueCallback -> unit

Parameters

script
String

the JavaScript to execute.

resultCallback
IValueCallback

A callback to be invoked when the script execution completes with the result of the execution (if any). May be null if no notification of the result is required.

Attributes

Remarks

Asynchronously evaluates JavaScript in the context of the currently displayed page. If non-null, resultCallback will be invoked with any result returned from that execution. This method must be called on the UI thread and the callback will be made on the UI thread.

Compatibility note. Applications targeting android.os.Build.VERSION_CODES#N or later, JavaScript state from an empty WebView is no longer persisted across navigations like #loadUrl(String). For example, global variables and functions defined before calling #loadUrl(String) will not exist in the loaded page. Applications should use #addJavascriptInterface instead to persist JavaScript objects across navigations.

Java documentation for android.webkit.WebView.evaluateJavascript(java.lang.String, android.webkit.ValueCallback<java.lang.String>).

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