2024-06-11 00:36:48 +00:00
|
|
|
@inject IJSRuntime JS
|
2024-06-13 04:46:24 +00:00
|
|
|
@inject State State
|
2024-06-14 07:20:04 +00:00
|
|
|
@inject RestService api
|
2024-06-11 00:36:48 +00:00
|
|
|
@if(Html != null) {
|
|
|
|
<iframe id="@id" frameborder="0" scrolling="no" srcdoc="@Html" onload="() => iframeResize({ license: 'GPLv3' })"></iframe>
|
|
|
|
}
|
|
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
2024-07-02 00:13:52 +00:00
|
|
|
public string? Url { get; set; }
|
2024-06-11 00:36:48 +00:00
|
|
|
[Parameter]
|
2024-07-02 00:13:52 +00:00
|
|
|
public string? id { get; set; }
|
2024-07-11 05:57:53 +00:00
|
|
|
[Parameter]
|
|
|
|
public string? SrcString { get; set; }
|
2024-06-13 04:46:24 +00:00
|
|
|
public MarkupString? Html { get; set; }
|
|
|
|
|
2024-06-11 00:36:48 +00:00
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender) {
|
|
|
|
if(firstRender){
|
|
|
|
await Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Reload() {
|
2024-07-02 00:13:52 +00:00
|
|
|
if (Url != null){
|
2024-06-11 00:36:48 +00:00
|
|
|
Html = await api.GetHtml(Url);
|
2024-07-11 05:57:53 +00:00
|
|
|
SrcString = Html?.ToString();
|
|
|
|
}
|
|
|
|
if(SrcString != null) {
|
|
|
|
SrcString = SrcString?.Replace("</head>", "<base target='_blank'></head>");
|
|
|
|
SrcString = SrcString?.Replace("</body>", "<script src='https://cdn.jsdelivr.net/npm/@iframe-resizer/child'></script></body>");
|
|
|
|
Html = (MarkupString)(SrcString ?? string.Empty);
|
2024-07-02 00:13:52 +00:00
|
|
|
}
|
2024-06-11 00:36:48 +00:00
|
|
|
await InvokeAsync(StateHasChanged);
|
2024-07-11 05:57:53 +00:00
|
|
|
await IframeResize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task IframeResize() {
|
|
|
|
await JS.InvokeVoidAsync("iframeResize", new { license = "GPLv3" });
|
2024-06-11 00:36:48 +00:00
|
|
|
}
|
|
|
|
}
|