BlazorFrame 1.0.1
See the version list below for details.
dotnet add package BlazorFrame --version 1.0.1
NuGet\Install-Package BlazorFrame -Version 1.0.1
<PackageReference Include="BlazorFrame" Version="1.0.1" />
<PackageVersion Include="BlazorFrame" Version="1.0.1" />
<PackageReference Include="BlazorFrame" />
paket add BlazorFrame --version 1.0.1
#r "nuget: BlazorFrame, 1.0.1"
#:package BlazorFrame@1.0.1
#addin nuget:?package=BlazorFrame&version=1.0.1
#tool nuget:?package=BlazorFrame&version=1.0.1
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 (can be enabled/disabled)
- 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
- Scrolling Control - Enable or disable scrolling within the iframe wrapper
- 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"
EnableAutoResize="true"
EnableScroll="false"
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"
EnableAutoResize="false"
EnableScroll="true"
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 |
EnableAutoResize |
bool |
true |
Whether to automatically resize the iframe based on content height |
EnableScroll |
bool |
false |
Whether to enable scrolling within the iframe wrapper |
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 can automatically adjust the iframe height based on the content inside when EnableAutoResize
is set to true
(default). The component:
- Monitors the iframe content document every 500ms
- Calculates the maximum height from various document properties
- Updates the iframe height dynamically
- Handles cross-origin restrictions gracefully
- Can be disabled by setting
EnableAutoResize="false"
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
}, '*');
Styling and CSS
The component includes built-in CSS styling with wrapper classes:
- iframe-wrapper - Applied to all iframe wrappers
- iframe-wrapper scrollable - Applied when
EnableScroll="true"
The wrapper provides:
- 100% width by default
- Hidden overflow (unless scrollable)
- Borderless iframe display
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)"
EnableAutoResize="false"
style="min-height: 400px;" />
</div>
Disabling Auto-Resize for Fixed Height
<BlazorFrame Src="@contentUrl"
Width="100%"
Height="500px"
EnableAutoResize="false"
EnableScroll="true" />
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 | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.16)
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.3.0 | 16 | 8/27/2025 |
2.1.2 | 436 | 7/12/2025 |
2.1.1 | 101 | 7/12/2025 |
2.1.0 | 101 | 7/11/2025 |
2.0.0 | 129 | 7/10/2025 |
1.4.0 | 124 | 7/7/2025 |
1.3.0 | 124 | 7/7/2025 |
1.2.2 | 128 | 7/7/2025 |
1.2.1 | 127 | 7/7/2025 |
1.2.0 | 128 | 7/7/2025 |
1.1.2 | 132 | 7/7/2025 |
1.1.1 | 126 | 7/7/2025 |
1.1.0 | 84 | 7/4/2025 |
1.0.1 | 93 | 7/4/2025 |
1.0.0 | 113 | 7/4/2025 |