Scenario is the following:
There's a page and an iframe within that page. Starting out, they're both from the same domain (origin). The iframe can contain links (or javascript that changes window.location.href) to other domains. I want to detect in the outer frame, when user navigates away from the original domain in iframe, to replace outer page's window.location.href with the URL that user navigated to, thus ending the application that was running in the outer frame.
Tried to use beforeunload event but the inner frame's location.href doesn't get changed. Also the iframe DOM element's src property doesn't change when its contentDocument changes.
Is my problem solvable in current browsers implementations or what approach would you use to get closest behaviour to the described one?