Bewerken

Delen via


WKWebView.EvaluateJavaScript Method

Definition

Overloads

EvaluateJavaScript(NSString, WKJavascriptEvaluationResult)

Evaluates the given JavaScript string.

EvaluateJavaScript(String, WKJavascriptEvaluationResult)

Evaluates JavaScript and calls back into C# with the results.

EvaluateJavaScript(NSString, WKJavascriptEvaluationResult)

Evaluates the given JavaScript string.

[Foundation.Export("evaluateJavaScript:completionHandler:")]
public virtual void EvaluateJavaScript (Foundation.NSString javascript, WebKit.WKJavascriptEvaluationResult completionHandler);
abstract member EvaluateJavaScript : Foundation.NSString * WebKit.WKJavascriptEvaluationResult -> unit
override this.EvaluateJavaScript : Foundation.NSString * WebKit.WKJavascriptEvaluationResult -> unit

Parameters

javascript
NSString

The JavaScript string to evaluate

completionHandler
WKJavascriptEvaluationResult

Method to invoke when script evaluation completes or fails

This parameter can be null.

Attributes

Remarks

The system calls completionHandler after evaluation. The arguments to the handler are an NSObject containing the results of the evaluation and an NSError if an error. If an error occurred, the result argument will be null. If no error occurred, the error argument will be null.

var config = new WKWebViewConfiguration();
var wk = new WKWebView(UIScreen.MainScreen.Bounds, config);
var js = (NSString) "document.getElementById('foo').innerHTML = 'bar'";
WKJavascriptEvaluationResult handler = (NSObject result, NSError err) => { 
  if(err != null)
  {
    System.Console.WriteLine(err);
  }
  if(result != null)
  {
     System.Console.WriteLine(result);
  }
};
wk.EvaluateJavaScript(js, handler);

Applies to

EvaluateJavaScript(String, WKJavascriptEvaluationResult)

Evaluates JavaScript and calls back into C# with the results.

public void EvaluateJavaScript (string javascript, WebKit.WKJavascriptEvaluationResult completionHandler);
member this.EvaluateJavaScript : string * WebKit.WKJavascriptEvaluationResult -> unit

Parameters

javascript
String
completionHandler
WKJavascriptEvaluationResult

Remarks

The system calls completionHandler after evaluation. The arguments to the handler are an NSObject containing the results of the evaluation and an NSError if an error. If an error occurred, the result argument will be null. If no error occurred, the error argument will be null.

var config = new WKWebViewConfiguration();
var wk = new WKWebView(UIScreen.MainScreen.Bounds, config);
var js = (NSString) "document.getElementById('foo').innerHTML = 'bar'";
WKJavascriptEvaluationResult handler = (NSObject result, NSError err) => { 
  if(err != null)
  {
    System.Console.WriteLine(err);
  }
  if(result != null)
  {
     System.Console.WriteLine(result);
  }
};
wk.EvaluateJavaScript(js, handler);

Applies to