我发现了一个类似的问题,但接受的答案不是我想要的: Using an iframe in jquery.simplemodal, the iframe reload when the popup is closed
我想首先将内容动态加载到 iframe 中,然后在完成加载后,使用 SimpleModal 显示它。我的问题是它似乎不断弹出。
我已将以下内容链接到一个按钮单击,它打开得很好(即使我不相信 iframe 内容在打开时实际上已经完成加载。)但是在漂亮的关闭动画之后,我看到 ajax 请求被重复了它弹回打开。
$.get('a/zong/299/' + number +"/", function(data) {
$(document.body).append('<iframe id="zong" src='+data+
' width="490" height="350" style="display:none;border:none;"></iframe>');
$('iframe#zong').load(function()
{
$('#zong').modal({
overlayCss: {backgroundColor:"#C4EFFF"},
containerCss:{
...
},
overlayClose:true,
onOpen: function(dialog){
dialog.overlay.fadeIn('slow', function(){
dialog.data.hide();
dialog.container.fadeIn('slow', function(){
dialog.data.slideDown('slow');
});
})
},
onClose: function(dialog){
dialog.data.fadeOut('slow', function(){
dialog.container.hide('slow', function(){
dialog.overlay.slideUp('slow', function(){
$.modal.close();
})
})
})
},
});
});
});
如您所见,生活相当复杂;)必须在服务器上生成 iframe 源,然后加载一个 iframe,并在对话失去焦点时破坏它。
PS:如果 stackoverflow 可以对复制粘贴的代码进行自动缩进,那就太好了,这需要很长时间!;)
我已经尝试$('#zong').attr('src', '');
在 onClose 函数中添加,但仍然没有运气,模态对话从不死者那里回来了。;)
谢谢您的帮助!