K. Biermann
K. Biermann

Reputation: 1318

Notice if user changes to iframe

Has someone an idea how I can check if the user works currently in the iframe? E. g. the user clicks into the iframe. I know that I can't get any information about the target but the iframe element it self is embedded into my website, so the question is: is there any way to detect if the user "activates" or "focuses" the iframe element? The "onactivate" and "onfocus" actions doesn't work in Chrome...

Edit: I want the parent window to detect if the user changes to the iframe. The frame is on my domain.

Upvotes: 2

Views: 108

Answers (1)

musically_ut
musically_ut

Reputation: 34288

If the content of the inner iframe are under your control, then you can try:

  1. Capture onclick and onfocus events on the <body> of the internal iframe
  2. Post a message to window.parent.
  3. On the parent, listen to that message and take appropriate action.

However, note that messaging is only supported IE8+.

Upvotes: 1

Related Questions