views:

55

answers:

1

If you set an unbeforeunload event inside an iframe, this is not triggered when you for instance click through to a link in the iframe. It works in IE and Firefox (not Opera, but Opera does not support onbeforeunload in general AFAIK).

Just wondering, am I doing something wrong? Should this behaviour not be possible? Or is it a bug in Google Chrome/webkit? Any workarounds?

Code example:

test.html:

<html>
  <body>
    <p>Main page content</p>
    <script type="text/javascript">
      window.onbeforeunload = function() {alert('unloadevent in main window');};
    </script>
    <iframe id="tpa" src="..test2.html"></iframe>
  </body>
</html>

test2.html:

<html>
  <body>
    <script type="text/javascript">
      self.onbeforeunload = function() {alert('unloadevent in frame window');};
    </script>
    <a href="http://www.google.com/"&gt;Link to for instance google</a>
  </body>
</html>
A: 

Seems it is an open issue in webkit (and not about to be fixed soon):

https://bugs.webkit.org/show_bug.cgi?id=19418

If anyone knows of workarounds, let me know.

AMO