Сервис:
Код: Выделить всё
public class InitialDocumentHtmlService : IInitialDocumentHtmlService
{
private readonly IJSRuntime runtime;
public InitialDocumentHtmlService(IJSRuntime jsRuntime)
{
this.runtime = jsRuntime;
}
public async Task GetColorAsync(CancellationToken token)
{
// here u get exeption
var helloword = await runtime.InvokeAsync("import", token,
"./test.js");
await helloword.InvokeVoidAsync("helloWorld", token);
}
}
Код: Выделить всё
export function helloWorld() {
console.log("Hello");
alert("hello");
}
Исключение:< /p>
Код: Выделить всё
This exception was originally thrown at this call stack:
Microsoft.AspNetCore.Components.WebView.Services.WebViewJSRuntime.BeginInvokeJS(long, string, string, Microsoft.JSInterop.JSCallResultType, long) in WebViewJSRuntime.cs
Microsoft.JSInterop.JSRuntime.InvokeAsync(long, string, System.Threading.CancellationToken, object[])
Microsoft.JSInterop.JSRuntime.InvokeAsync(string, System.Threading.CancellationToken, object[])
Microsoft.JSInterop.JSRuntimeExtensions.InvokeAsync(Microsoft.JSInterop.IJSRuntime, string, System.Threading.CancellationToken, object[])
Datanex.Frontend.App.Modules.Services.InitialDocumentHtmlService.GetColorAsync(System.Threading.CancellationToken) in InitialDocumentHtmlService.cs
Datanex.Frontend.App.Modules.Services.InitialApp.InitAsync(System.Threading.CancellationToken) in InirialApp.cs
Datanex.Frontend.App.Component.Pages.Login.OnInitializedAsync() in Login.razor
Невозможно вызвать JavaScript вне контекста WebView.
В чем причина этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/777 ... ning-javas
Мобильная версия