Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor server, copy to clipboard is failing in Safari

$
0
0

I added some simple functionality to copy a link to the clipboard, it works fine in Edge and Chrome but is failing in Safari with the following error:

The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

I believe this is because Safari wants you to do it via the click event and Blazor is routing the request through it's interop layer.

Has anyone got this to work?

Sample code:

Razor:

<button title="Copy link to clipboard" @onclick="@(e=> CopyToClipboard("someText"))">Copy</button>

C#:

        private async Task CopyToClipboard(string textToCopy)        {            await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", textToCopy);        }

I had the javascript call in a separate javascript file, in a function, but was getting the same result.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>