CurrieTechnologies.Razor.Clipboard 1.4.0

Install-Package CurrieTechnologies.Razor.Clipboard -Version 1.4.0
dotnet add package CurrieTechnologies.Razor.Clipboard --version 1.4.0
<PackageReference Include="CurrieTechnologies.Razor.Clipboard" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CurrieTechnologies.Razor.Clipboard --version 1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CurrieTechnologies.Razor.Clipboard, 1.4.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CurrieTechnologies.Razor.Clipboard as a Cake Addin
#addin nuget:?package=CurrieTechnologies.Razor.Clipboard&version=1.4.0

// Install CurrieTechnologies.Razor.Clipboard as a Cake Tool
#tool nuget:?package=CurrieTechnologies.Razor.Clipboard&version=1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CurrieTechnologies.Razor.Clipboard

This package provides Blazor applications with access to the browser's Clipboard API

This package is for Blazor Server Apps and Blazor WebAssembly Apps. It should be used instead of CurrieTechnologies.Blazor.Clipboard which is now deprecated.

Usage

  1. In your Blazor app, add the CurrieTechnologies.Razor.Clipboard NuGet package

    Install-Package CurrieTechnologies.Razor.Clipboard
    
  2. In your Blazor app's Startup.cs, register the 'ClipboardService'.

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddClipboard();
        ...
    }
    
  3. Add this script tag in your root html file (Likely _Host.cshtml for Blazor Server Apps or index.html for Blazor WebAssembly Apps), right under the framework script tag. (i.e <script src="_framework/blazor.server.js"></script> for Blazor Server Apps or <script src="_framework/blazor.webassembly.js"></script> for Blazor WebAssembly Apps)

    <script src="_content/CurrieTechnologies.Razor.Clipboard/clipboard.min.js"></script>
    
  4. Now you can inject the ClipboardService into any Blazor page and use it like this:

    @using CurrieTechnologies.Razor.Clipboard
    @inject ClipboardService clipboard
    
    <input @bind="textValue" />
    <button @onclick="(async e => await clipboard.WriteTextAsync(textValue))">Copy To Clipboard</button>
    <button @onclick="(async e => textValue = await clipboard.ReadTextAsync())">Paste From Clipboard</button>
    
    @code
    {
        string textValue = string.Empty;
    }
    

Compatibility

Chrome Edge Legacy Edge (Chromium) Firefox IE Opera Safari
✔️ 63+ ✔️ ❌* ✔️ 53+ ✔️ 13.1+

* Firefox does support the clipboard API, but in a very restricted way that Blazor doesn't support.

Clipboard API Gotchas

The Clipboard API is a relatively new API and presents some security concerns, so keep these in mind.

  1. Clipboard events can only be raised in response to user input.
  2. Focus must be on the DOM window. (not the debugger, or another window)
  3. The page must be served over HTTPS

References

Unblocking Clipboard Access

Clipboard API

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on CurrieTechnologies.Razor.Clipboard:

Repository Stars
noahc3/SDSetup
The Ninite for your Nintendo Switch.
Version Downloads Last updated
1.4.0 365 10/22/2021
1.3.1 19,821 7/31/2020
1.3.0 1,988 6/5/2020
1.2.3 1,614 5/13/2020
1.2.2 1,083 3/31/2020
1.2.1 2,803 1/15/2020
1.2.0 1,442 12/3/2019
1.1.0 577 9/30/2019
1.0.0 266 9/23/2019
0.5.0 179 9/17/2019
0.4.0 181 9/5/2019
0.3.0 203 8/13/2019
0.2.0 187 7/24/2019
0.1.0 306 6/14/2019

enable multi-targetting