成功后使用 iframe 关闭模式



我有一个内部带有iframe的Bootstrap模式。 该 iframe 中有一个带有上传者的联系表单。我想在提交表单时关闭模式。

你是怎么做到的?

我尝试使用

success:function(){
$('#modal .close', parent.document).trigger('click');
}

但这显然被阻止了跨域访问。

模态:

<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">{{ 'Vraag uw beregeningsplan aan' | t }}</h4>
</div>
<div class="modal-body">
<iframe></iframe>
</div>

</div>
</div>
</div>

<script>
$(document).ready(function() {
$('#modal').on('shown.bs.modal',function(){
$(this).find('iframe').attr('src','//link-to-form/')
});
});
</script>

任何帮助表示赞赏!

好吧,从描述中不确定iframe中的表单是您自己的表单还是某些外部Web表单。

如果是你自己的形式,那么在内部表单中编写这个jquery代码

$(document).ready(function () {
$(document).on('submit', '#myForm', function () {                    
window.parent.$('#modal').modal('hide');
});
});

其中 myForm 是内部表单的 ID

最新更新