This code will help you to understand how to find the property of the window when calling the JavaScript method in Blazor using JS interop.
You have to refer to the JavaScript method implemented JS (external-script.js) file in index.html properly and then call the function from .NET using IJSRuntime.
[wwwroot/index.html]
<body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script src="external-script.js"></script> </body>
[wwwroot/external-script.js]
window.methods = { print: function (message) { return "from js " + message } }
[Pages/Index.razor]
@inject IJSRuntime JSRuntime @code { private async void PrintMessage() { Console.WriteLine(await JSRuntime.InvokeAsync<string>("methods.print", "here is the message")); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
You have to refer to the JavaScript method implemented JS (external-script.js) file in index.html properly and then call the function from .NET using IJSRuntime.
[wwwroot/index.html]
[wwwroot/external-script.js]
[Pages/Index.razor]
need an explanation for this answer? contact us directly to get an explanation for this answer