WKWebView.EvaluateJavaScriptAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| EvaluateJavaScriptAsync(NSString) |
Evaluates the given JavaScript string. |
| EvaluateJavaScriptAsync(String) |
Evaluates the given JavaScript string. |
| EvaluateJavaScriptAsync(String, WKFrameInfo, WKContentWorld) |
EvaluateJavaScriptAsync(NSString)
Evaluates the given JavaScript string.
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public virtual System.Threading.Tasks.Task<Foundation.NSObject> EvaluateJavaScriptAsync(Foundation.NSString javascript);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
abstract member EvaluateJavaScriptAsync : Foundation.NSString -> System.Threading.Tasks.Task<Foundation.NSObject>
override this.EvaluateJavaScriptAsync : Foundation.NSString -> System.Threading.Tasks.Task<Foundation.NSObject>
Parameters
- javascript
- NSString
The JavaScript string to evaluate
Returns
A task that represents the asynchronous EvaluateJavaScript operation. The value of the TResult parameter is a WKJavascriptEvaluationResult.
- Attributes
Remarks
This method will throw a NSErrorException if the JavaScript is not evaluated successfully.
var config = new WKWebViewConfiguration();
var wk = new WKWebView(UIScreen.MainScreen.Bounds, config);
var js = (NSString) "document.getElementById('foo').innerHTML = 'bar'";
var result = await wk.EvaluateJavaScriptAsync(js); //== "bar"
The EvaluateJavaScriptAsync method is suitable to be used with C# async by returning control to the caller with a Task representing the operation.
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 is not null)
{
System.Console.WriteLine(err);
}
if(result is not null)
{
System.Console.WriteLine(result);
}
};
wk.EvaluateJavaScript(js, handler);
Applies to
EvaluateJavaScriptAsync(String)
Evaluates the given JavaScript string.
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public System.Threading.Tasks.Task<Foundation.NSObject> EvaluateJavaScriptAsync(string javascript);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
member this.EvaluateJavaScriptAsync : string -> System.Threading.Tasks.Task<Foundation.NSObject>
Parameters
- javascript
- String
A well-formed JavaScript expression.
Returns
A task that represents the asynchronous EvaluateJavaScript operation. The TResult holds the results of the evaluation.
- Attributes
Remarks
This method will throw a NSErrorException if the JavaScript is not evaluated successfully.
var config = new WKWebViewConfiguration();
var wk = new WKWebView(UIScreen.MainScreen.Bounds, config);
var js = (NSString) "document.getElementById('foo').innerHTML = 'bar'";
var result = await wk.EvaluateJavaScriptAsync(js); //== "bar"
Applies to
EvaluateJavaScriptAsync(String, WKFrameInfo, WKContentWorld)
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public virtual System.Threading.Tasks.Task<Foundation.NSObject> EvaluateJavaScriptAsync(string javaScriptString, WebKit.WKFrameInfo? frame, WebKit.WKContentWorld contentWorld);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
abstract member EvaluateJavaScriptAsync : string * WebKit.WKFrameInfo * WebKit.WKContentWorld -> System.Threading.Tasks.Task<Foundation.NSObject>
override this.EvaluateJavaScriptAsync : string * WebKit.WKFrameInfo * WebKit.WKContentWorld -> System.Threading.Tasks.Task<Foundation.NSObject>
Parameters
- javaScriptString
- String
- frame
- WKFrameInfo
- contentWorld
- WKContentWorld
Returns
- Attributes