如何捕获iframe的关闭事件

在A页面中:
[code="html"]

[/code]

在B页面中
[code="html"]
$(window).on('beforeunload', function(){
return 'Are you sure you want to leave?';
});
[/code]

单独打开B页面的时候,B页面中的beforeunload是可用的,但是如果在A页面中用一下的方式“关闭”B页面就没有用了:
[code="html"]
$("#idoftab").remove();
[/code]
我在A页面中尝试在remove之前手动调用iframe的unload方法,但是没用。

求解,万分感谢!

如果不是调用$("#idoftab").remove();

单独打开子页面或者父页面,在关闭页面的时候都会弹出确认对话框。

我大概都尝试了下,快要逼疯了。实在不行就在$("#idoftab").remove();之前
弹出对话确认下。

[code="java"]

$.messager.confirm('Confirm', 'Are you sure to exit this system?', function(r){
if (r){
// exit action;
}
});
[/code]

试试调用iframe的close方法来关闭iframe,能不能触发beforeunload

没弄过,但是不是可以在A页面里,页面加载的时候就对iframe加个类似于B页面里的监听方法。。