1

I saw the response given here:

How to rightly detect iframe was loaded with response 204 No Content?

but it didn't help.

It is possible, to check (using events, not checking a content of an iframe), that iframe was loaded (request was send)?

Example:

stackblitz

3 Answers3

1

You can detect the load event of an iframe, but not the status of 204 unless you use a fetch or xmlhttprequest. This still cannot be perfect because that website's httpheader may allow for it be embedded in iframes but not fetched.

myjobistobehappy
  • 736
  • 5
  • 16
0

You could use iframe onLoad event and can detect if the iframe has been loaded.

Example:

 <iframe src="https://fr.wikipedia.org/wiki/Main_Page" onLoad="(() => console.log('Loaded'))()" />
Sohail Ashraf
  • 10,078
  • 2
  • 26
  • 42
-1

this is what i managed to do. i grabbed the iframe element with ElementRef.

html:

<iframe #iframe name="blah" id="blah" src="https://httpstat.us/204"></iframe>

ts:

@ViewChild("iframe") iframe: ElementRef;

end AfterViewInit i am checking if the src string ends with '204'.

  ngAfterViewInit(): void {
    const src = this.iframe.nativeElement.getAttribute("src");
    if (src.endsWith("204")) {
      console.log("iframe loading failed");
    } else {
      console.log("iframe load succesfuly");
    }
  }

see here: stack blitz