Hi,
finaly a Forum just for Blazor :) Thank you!!!
Blazor Serverside
I do have a question that my be someone could answere. I do want to check if a iframe is finished loading. I tried and searched, but I think at the moment it is not possible to pass a Event happenig (in my case the js: .onload) in Js to Blazor.
I did come up with a workaround I thought.
I did the following
js.file:
var loaded = false;
function ResetLoadingFlag() {
loaded = false;
}
document.getElementById('myFrame').onload = function () { LoadingFinished() };
function LoadingFinished() {
loaded=true;
}
function JSGetMyIsLoadedFlag() {
return loaded;
}
and in in Blazor page:
@page "/"
@inject IJSRuntime jsRuntime
<div>
<div class="col-md-6">
<button type="button" class="btn btn-info" @onclick="GetMyFlagCSharp">Has iFrame Loaded</button>
</div>
@myBool
</div>
<div>
@*<iframe id="myFrame" src="/MyExternalHtmlPages/test.html"></iframe>*@
<iframe id="myFrame" src="https://www.spiegel.de"></iframe>
</div>
@code{
bool myBool;
private async Task GetMyFlagCSharp()
{
myBool = await jsRuntime.InvokeAsync<bool>("JSGetMyIsLoadedFlag");
}
}
I thought this way I could atleast check in Blazor the state of DOM element iFrame, but it is not working.
My observation is that the problem is somewhere around this line in the js-file:
document.getElementById('myFrame').onload = function () { LoadingFinished() };
The debugger gets to this line but the js function LoadingFinished() is never called.
I did make it even more simpler with
document.getElementById('myFrame').onload = function () { alert('yesLoaded') };
no callback etc. but that alert is never shown in Blazor.
BUT
If I check the same js in a normal Html-Page everthing works: Flag is set and/or Alert is shown.
Why cant Blazor show that alert? How can I achieve this behavior?
Thanks for help... and lets make Blazor happening (my only way to do some FrontEnd (because I do have no clue about js):)