iframe 内に unbeforeunload イベントを設定した場合、たとえば iframe 内のリンクをクリックしても、これはトリガーされません。IE と Firefox で動作します (Opera ではありませんが、Opera は一般的に onbeforeunload をサポートしていません)。
不思議に思うのですが、私は何か間違ったことをしていますか?この動作は可能ではないでしょうか? それとも Google Chrome/webkit のバグですか? 回避策はありますか?
コード例:
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/">Link to for instance google</a>
</body>
</html>