BlazorFrame 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazorFrame --version 1.0.0
                    
NuGet\Install-Package BlazorFrame -Version 1.0.0
                    
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="BlazorFrame" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorFrame" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BlazorFrame" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorFrame --version 1.0.0
                    
#r "nuget: BlazorFrame, 1.0.0"
                    
#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.
#:package BlazorFrame@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorFrame&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BlazorFrame&version=1.0.0
                    
Install as a Cake Tool

BlazorFrame

A Blazor component that provides an enhanced iframe wrapper with automatic resizing, cross-frame communication, and seamless JavaScript interop.

Features

  • Automatic Height Adjustment - Dynamically resizes iframe based on content height
  • Cross-Frame Messaging - Built-in support for postMessage communication
  • Event Callbacks - OnLoad and OnMessage event handling
  • Flexible Styling - Customizable width, height, and additional attributes
  • JavaScript Interop - Seamless integration with Blazor's JS interop
  • Disposal Pattern - Proper cleanup of resources and event listeners

Installation

Install the package via NuGet Package Manager:

dotnet add package BlazorFrame

Or via Package Manager Console:

Install-Package BlazorFrame

Usage

Basic Usage

@using BlazorFrame

<BlazorFrame Src="https://example.com" />

Advanced Usage with Event Handling

@using BlazorFrame

<BlazorFrame Src="@iframeUrl"
            Width="100%"
            Height="400px"
            OnLoad="HandleIframeLoad"
            OnMessage="HandleIframeMessage"
            class="my-custom-iframe" />

@code {
    private string iframeUrl = "https://example.com";

    private Task HandleIframeLoad()
    {
        Console.WriteLine("Iframe loaded successfully!");
        return Task.CompletedTask;
    }

    private Task HandleIframeMessage(string messageJson)
    {
        Console.WriteLine($"Received message: {messageJson}");
        
        // Parse and handle the message
        var message = JsonSerializer.Deserialize<dynamic>(messageJson);
        
        return Task.CompletedTask;
    }
}

Custom Styling and Attributes

<BlazorFrame Src="@iframeUrl"
            Width="800px"
            Height="600px"
            class="border rounded shadow"
            style="margin: 20px;"
            sandbox="allow-scripts allow-same-origin" />

Parameters

Parameter Type Default Description
Src string "" The URL to load in the iframe
Width string "100%" The width of the iframe
Height string "600px" The initial height of the iframe
OnLoad EventCallback - Callback fired when the iframe loads
OnMessage EventCallback<string> - Callback fired when receiving postMessage
AdditionalAttributes Dictionary<string, object> - Additional HTML attributes to apply

Automatic Resizing

BlazorFrame automatically adjusts the iframe height based on the content inside. The component:

  1. Monitors the iframe content document every 500ms
  2. Calculates the maximum height from various document properties
  3. Updates the iframe height dynamically
  4. Handles cross-origin restrictions gracefully

Cross-Frame Communication

The component supports bidirectional communication through the browser's postMessage API:

Receiving Messages from Iframe

Messages sent from the iframe content are automatically captured and forwarded to your OnMessage callback:

// Inside your iframe content
window.parent.postMessage({ 
    type: 'custom', 
    data: 'Hello from iframe!' 
}, '*');

Special Resize Messages

Send resize messages from iframe content to manually control height:

// Inside your iframe content
window.parent.postMessage({ 
    type: 'resize', 
    height: 800 
}, '*');

Requirements

  • .NET 8.0 or later
  • Blazor Server or Blazor WebAssembly

Browser Support

BlazorFrame works in all modern browsers that support:

  • ES6 modules
  • postMessage API
  • Blazor JavaScript interop

Examples

Loading Different Content Types


<BlazorFrame Src="https://docs.microsoft.com" />


<BlazorFrame Src="./local-content.html" />


<BlazorFrame Src="data:text/html,<h1>Hello World!</h1>" />

Responsive Design

<div class="container-fluid">
    <BlazorFrame Src="@contentUrl"
                Width="100%"
                Height="calc(100vh - 200px)"
                style="min-height: 400px;" />
</div>

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.2 98 7/12/2025
2.1.1 92 7/12/2025
2.1.0 91 7/11/2025
2.0.0 122 7/10/2025
1.4.0 117 7/7/2025
1.3.0 117 7/7/2025
1.2.2 120 7/7/2025
1.2.1 119 7/7/2025
1.2.0 120 7/7/2025
1.1.2 126 7/7/2025
1.1.1 119 7/7/2025
1.1.0 75 7/4/2025
1.0.1 84 7/4/2025
1.0.0 104 7/4/2025