如果您在 iframe 中设置 unbeforeunload 事件,则不会在您点击进入 iframe 中的链接时触发此事件。它适用于 IE 和 Firefox(不是 Opera,但 Opera 通常不支持 onbeforeunload AFAIK)。
只是想知道,我做错了什么吗?这种行为不应该是可能的吗?还是 Google Chrome/webkit 中的错误?任何解决方法?
代码示例:
测试.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>
测试2.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>