I have a page that has a bunch of different iframes (A, B, C, D) - all of which are fully visible at all times. Together, they make up the various portions of my application's UI. One of these iframes, iframe D - houses another, smaller iframe (iframe X) that is sometimes made visible by a user action. It should automatically disappear whenever the user clicks outside of it. I can easily handle this from within iframe D by putting an onclick on the body. If I actually detect a click in iframe D's body - that means they aren't clicking in iframe X, so I can hide iframe X via CSS. No problem.
The problem is the other iframes - A, B, and C. If a user clicks within those, I want to hide iframe X also. Currently, I have it working - but not well. For each of those iframes (A, B, C), I have code that will communicate body clicks to iframe D. I don't like this approach because iframes A, B, C all have knowledge of iframe X - there really should be no need for this, and it just adds to files I have to change to support the feature offered by iframe X. Is there any way I can handle detecting external onclick events all from within iframe D? This would leave the iframe X show/hide logic within iframe D, which makes the code much easier to move around.
If I get that onclick monitoring going - I'm also wondering if it would handle all clicks - for example, if iframe A has some onclick events set on specific elements - am I sure to also catch those clicks? I mention this because my current workaround seems to be flawed (iframes A, B, C report their body onclicks to iframe D) - certain clicks are not triggering body onclick.
Thanks in advance guys. Please keep in mind, though, that removing iframes isn't realistic at this point in the project.