Question

I'm wondering if I have a page, that contains multiple iFrames and if I'm communicating through modification of the iFrame src attribute, would it be possible to set a hashChange listener on the src attribute.

Of course this would have to be inside the iFrame code, but trying this:

  $(document).ready(function () {  
    console.log(window);
    $(window).on('hashchange', function() {
      console.log("IFRAME HASH CHANGED");
    });
   });

Does not trigger anything.

Question:
Any idea if this is possible? If not, how else could it be done?

Thanks for inputs!

Was it helpful?

Solution

The code above is fine. You should have no issues setting a hashchange event listener on the iframe's window. The problem is that you are viewing the console for the parent window. For example, if you change your console.log to an alert, you will see that it is in fact working.

If you're using google chrome's developer tools, you can click on this drop-down to switch between which window context you are in:

Screenshot of chrome developer tools

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top