From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

HybridWebView calling JavaScript from C#

HybridWebView calling JavaScript from C#

- [Narrator] One of the important capabilities of the HybridWebView is the ability to call JavaScript from C#. To do this is relatively easy once we know how to do it, However, there are some steps that need to be taken for it to work correctly. The first thing we need to do to allow JavaScript to be called from C#, or to call C# from JavaScript, is to add a JavaScript file to the project. And we're going to start by adding a folder to it. And we're going to do this right under our ww root folder, and we'll right-click and go Add New Folder. And we're going to call it scripts. And inside scripts we're going to add a new file. Now, normally I'd add a new JavaScript file. I don't actually have the web workload installed, so that doesn't show up for us. So I'm just going to change this JSON file right here. And we're just going to call it HybridWebView.js And we're going to clean out the content of this, and make it an empty JavaScript file, and hit Save. Now what needs to be in this…

Contents