diff --git a/docs/user-interface/controls/hybridwebview.md b/docs/user-interface/controls/hybridwebview.md index 5a9939e48..22eb33d4a 100644 --- a/docs/user-interface/controls/hybridwebview.md +++ b/docs/user-interface/controls/hybridwebview.md @@ -21,7 +21,7 @@ The .NET Multi-platform App UI (.NET MAUI) defines a event that's raised when a raw message is received. The object that accompanies the event defines a property that contains the message. -Your app's C# code can invoke synchronous and asynchronous JavaScript methods within the with the and methods. For more information, see [Invoke JavaScript from C#](#invoke-javascript-from-c). Your app's JavaScript code can also synchronously invoke C# methods. For more information, see [Invoke C# from JavaScript](#invoke-c-from-javascript). +Your app's C# code can invoke synchronous and asynchronous JavaScript methods within the with the and methods. Your app's JavaScript code can also synchronously invoke C# methods. For more information, see [Invoke JavaScript from C#](#invoke-javascript-from-c) and [Invoke C# from JavaScript](#invoke-c-from-javascript). To create a .NET MAUI app with you need: @@ -32,7 +32,7 @@ To create a .NET MAUI app with you The entire app, including the web content, is packaged and runs locally on a device, and can be published to applicable app stores. The web content is hosted within a native web view control and runs within the context of the app. Any part of the app can access external web services, but isn't required to. > [!IMPORTANT] -> By default, the won't be available when full trimming or Native AOT is enabled. To change this behavior, see [Trimming feature switches](~/deployment/trimming.md#trimming-feature-switches). +> By default, the control won't be available when full trimming or Native AOT is enabled. To change this behavior, see [Trimming feature switches](~/deployment/trimming.md#trimming-feature-switches). ## Create a .NET MAUI HybridWebView app @@ -425,14 +425,14 @@ internal partial class HybridSampleJSContext : JsonSerializerContext Your app's JavaScript code within the can synchronously invoke C# methods, with optional parameters and an optional return value. This can be achieved by: -- Declaring public methods that will be invoked from JavaScript. -- Setting the object that will be the target of JavaScript calls from the , with the method. +- Declaring public C# methods that will be invoked from JavaScript. +- Calling the method to set the object that will be the target of JavaScript calls from the . - Calling the C# methods from JavaScript. > [!IMPORTANT] > Asynchronously invoking C# methods from JavaScript isn't currently supported. -The following example shows four methods that will be invoked from JavaScript: +The following example shows four public methods that can be invoked from JavaScript: ```csharp public partial class MainPage : ContentPage @@ -473,7 +473,7 @@ public partial class MainPage : ContentPage } ``` -You must then set the object that will be the target of JavaScript calls from the , with the method: +You must then call the method to set the object that will be the target of JavaScript calls from the : ```csharp public partial class MainPage : ContentPage @@ -483,10 +483,12 @@ public partial class MainPage : ContentPage InitializeComponent(); hybridWebView.SetInvokeJavaScriptTarget(this); } + + ... } ``` -The public methods on the object that's the target of JavaScript calls can then be invoked using the `window.HybridWebView.InvokeDotNet` JavaScript function: +The public methods on the object set via the method can then be invoked from JavaScript with the `window.HybridWebView.InvokeDotNet`function: ```js await window.HybridWebView.InvokeDotNet('DoSyncWork'); @@ -496,3 +498,6 @@ const retValue = await window.HybridWebView.InvokeDotNet('DoSyncWorkParamsReturn ``` The `window.HybridWebView.InvokeDotNet` JavaScript function invokes a specified C# method, with optional parameters and an optional return value. + +> [!NOTE] +> Invoking the `window.HybridWebView.InvokeDotNet` JavaScript function requires your app to include the *HybridWebView.js* JavaScript library listed earlier in this article.