Razor.Clipboard
Razor.Clipboard copied to clipboard
Can clipbnoard be used without lambda function?
In a blazor server app I've tried to use a "normal" function to access the clipboard, instead of the lambda function per your example
@page "/Clipboard" @using CurrieTechnologies.Razor.Clipboard @inject ClipboardService clipboard
<PageTitle>cliptest</PageTitle> <button @onclick="myfunc">myfunc
@code private async void myfunc(MouseEventArgs e) { string a = await clipboard.ReadTextAsync(); }
your minified js is included in the page via the _host.cshtml but I get an exception when I click my button
Exception has occurred: CLR/Microsoft.JSInterop.JSException
Exception thrown: 'Microsoft.JSInterop.JSException' in System.Private.CoreLib.dll:
'Document is not focused.
undefined'
at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16
1.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at CurrieTechnologies.Razor.Clipboard.ClipboardService.<ReadTextAsync>d__4.MoveNext()
at blazorWeb.Pages.Clipboard.
Is this "document not focused" the reason you had to use a lambda function, or should my code work?