I want identify in an HTML document whether an Iframe has loaded or not.
Here is what I tried, but I am pretty not sure if this is the right way to identify the loading of IFrame:
var myhtmlDocument = (IHTMLDocument2) HtmlDocument.DomDocument;
IHTMLSelectionObject htmlselectionObject = myhtmlDocument.selection;
bool frameloaded = false;
if (htmlselectionObject != null)
{
FramesCollection frames = myhtmlDocument.frames;
IHTMLSelectionObject frameSelection = frame.document.selection;
for (int i = 0; i < frames.length; i++)
{
object index = i;
IHTMLWindow2 frame = (IHTMLWindow2) frames.item(ref index);
IHTMLSelectionObject frameSelection = frame.document.selection;
if(frameSelection)
frameloaded = true;
}
}
The object model you are using is deprecated because it's based on Internet Explorer.
If you're able to switch to using the modern WebView2 (Edge based) object then you can listen for the CoreWebView2.NavigationCompleted Event
If you're really stuck with IHTMLDocument2 then you would have to do a similar thing with addEventListener
Where
listeneris a compatible event handler that will act upon the page load event.