Blazor.Javascript.Interop.Extensions 1.0.4

dotnet add package Blazor.Javascript.Interop.Extensions --version 1.0.4                
NuGet\Install-Package Blazor.Javascript.Interop.Extensions -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazor.Javascript.Interop.Extensions" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazor.Javascript.Interop.Extensions --version 1.0.4                
#r "nuget: Blazor.Javascript.Interop.Extensions, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Blazor.Javascript.Interop.Extensions as a Cake Addin
#addin nuget:?package=Blazor.Javascript.Interop.Extensions&version=1.0.4

// Install Blazor.Javascript.Interop.Extensions as a Cake Tool
#tool nuget:?package=Blazor.Javascript.Interop.Extensions&version=1.0.4                

Blazor.Javascript.Interop

Overview

Blazor.Javascript.Interop is a NuGet package designed as an extension library specifically for Blazor projects. It facilitates seamless interoperability between C# code in Blazor and JavaScript, empowering developers to incorporate JavaScript functionalities into their Blazor applications effortlessly.

Features

  • Interoperability: Enables smooth communication between C# code in Blazor and JavaScript.
  • Simplified Integration: Facilitates easy incorporation of JavaScript functionalities into Blazor applications.
  • Boosted Productivity: Streamlines development workflows by eliminating complexities in bridging the gap between C# and JavaScript.

Installation

To install Blazor.Javascript.Interop, simply add the package to your Blazor project via NuGet Package Manager or the .NET CLI:

dotnet add package Blazor.Javascript.Interop

Usage

After installing the package, you can start using it in your Blazor project by following these steps:

  1. Import the Namespace: Import the Blazor.Javascript.Interop namespace in your Blazor components where you intend to utilize JavaScript interop functionalities.

    @using Blazor.Javascript.Interop;
    @using Blazor.Javascript.Interop.Extensions;
    
  2. Wrap your Router: Wrap the router component with the <WindowCascadingValue> component

    // Example of invoking a JavaScript function from C# code
    <WindowCascadingValue>
        <Router AppAssembly="typeof(Program).Assembly">
            <Found Context="routeData">
                <RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
                <FocusOnNavigate RouteData="routeData" Selector="h1" />
            </Found>
        </Router>
    </WindowCascadingValue>
    
  3. Get the JSWindow object: Utilize the provided methods to invoke JavaScript functions from your C# code.

    [CascadingParameter]
    public required JSWindow Window { get; set; }
    
  4. Use the javascript methods: Check what are the methods ported to C# from javascript

    private async Task CookieEnabledAsync() => cookieEnabled = await Window.Navigator.CookieEnabledAsync();
    

Compatibility

Blazor.Javascript.Interop is compatible with Blazor projects targeting both server-side and client-side hosting models.

Contributing

Contributions to Blazor.Javascript.Interop are welcome! If you have any ideas for improvements, new features, or encounter any issues, feel free to open an issue or submit a pull request on GitHub.

License

Blazor.Javascript.Interop is licensed under the MIT License.

Acknowledgements

This project is inspired by the growing need for seamless integration between C# and JavaScript in Blazor applications. Special thanks to the Blazor community for their continuous support and feedback.


Note: For more information, detailed examples, and updates, please refer to the GitHub repository. We appreciate your interest and hope Blazor.Javascript.Interop proves to be a valuable addition to your Blazor development toolkit!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Blazor.Javascript.Interop.Extensions:

Package Downloads
Blazor.Javascript.Interop

Blazor.Javascript.Interop is a NuGet package designed as an extension library specifically for Blazor projects. It facilitates seamless interoperability between C# code in Blazor and JavaScript, empowering developers to incorporate JavaScript functionalities into their Blazor applications effortlessly.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 97 9/23/2024
1.0.3 87 9/22/2024
1.0.2 84 9/20/2024
1.0.1 82 9/20/2024
1.0.0 89 9/20/2024
0.0.14 86 9/20/2024
0.0.13 83 9/20/2024
0.0.12 99 9/16/2024
0.0.11 96 9/16/2024
0.0.9 101 9/15/2024
0.0.8 97 9/12/2024
0.0.4 106 9/11/2024
0.0.3.3 160 4/12/2024
0.0.3.2 101 4/12/2024
0.0.3.1 103 4/12/2024
0.0.3 103 4/12/2024
0.0.2 103 4/9/2024
0.0.1 127 3/27/2024
0.0.1-beta 72 3/27/2024