BlazorFrame 1.0.0
See the version list below for details.
dotnet add package BlazorFrame --version 1.0.0
NuGet\Install-Package BlazorFrame -Version 1.0.0
<PackageReference Include="BlazorFrame" Version="1.0.0" />
<PackageVersion Include="BlazorFrame" Version="1.0.0" />
<PackageReference Include="BlazorFrame" />
paket add BlazorFrame --version 1.0.0
#r "nuget: BlazorFrame, 1.0.0"
#:package BlazorFrame@1.0.0
#addin nuget:?package=BlazorFrame&version=1.0.0
#tool nuget:?package=BlazorFrame&version=1.0.0
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:
- 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
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 | 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.