1

It is possible to detect when <iframe> leaves a page, provided you have access to that page:

IFRAME.contentWindow.addEventListener("unload", function() {
  parent.console.log("Unloading.");
});

But this requires that

  • You have access to the inner page (I have, but still...)
  • There is some inner window
  • You wait for the frame to load to assign this event, so the actual code is:

    fr.onload = function() {
      this.contentWindow.addEventListener("unload", function() {
        parent.console.log("Unload.");
      });
      console.log("Load");
    }
    
  • ... and the onload event takes very very very long on modern pages (due to stupid facebook like plugins and similar stuff).

I am making an userscript and the requirement is that I am detect when, within the <iframe> document starts being loaded, the moment when javascript is already working in that document. If this is not possible, then at least the event when the webpage has been loaded and is only waiting for asynchronous data (CSS, images, IFRAMEs).

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • If you have access to both the parent and the iframe, I would suggest working with a postmessage (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) and have the iframe send it's state to the parent. Much cleaner imo and easier when it comes to SOP. – Pevara May 08 '15 at 21:16
  • Not possible. I have javascript access to both, but can only edit the top window. – Tomáš Zato May 08 '15 at 23:00
  • @TomášZato See http://stackoverflow.com/q/23766086/2801559 , http://stackoverflow.com/q/24338564/2801559 – guest271314 May 09 '15 at 00:04

0 Answers0