[英]Close iframe in colorbox after submit the form
我正在开发一个网站,首次访问该网站时,将要求用户输入电子邮件以及他/她居住的城市。 我使用colorbox和iframe加载了它。 这是main.php中的代码:
Yii::app()->clientScript->registerScript('',
"$('document').ready(
function()
{
$.fn.colorbox({href:'http://www.veevou.com/visitor/create',
iframe:true,'width':'365px', 'height':'510px', onClosed:function(){ location.reload(true); }});
}
)");
$colorbox = $this->widget('application.extensions.colorpowered.ColorBox');
$colorbox
->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'80%'));
因此,您会看到,颜色框将呈现页面create.php,并且在提交表单后,控制器将保存数据,然后重定向到索引页面。
这是控制器:
if(isset($_POST['Visitor']))
{
$model->attributes=$_POST['Visitor'];
// Register only if he / she is not registered as member nor visitor
if($model->save())
{
echo "<script>parent.$.fn.colorbox.close(); </script>";
$this->redirect(array('site/index'));
}
}
else
{
$this->render('form',compact('model'));
}
但是它说“无法修改已经发送的标题...”。 如何关闭颜色框? 我尝试将“ parent。$。fn.colorbox.close();”放在重定向到另一个页面之前,但是没有用。 我应该将$ .fn.colorbox.close()放在哪里? 我在另一篇文章中尝试了几种方法,但没有一种对我有用。 谢谢
你的问题是这部分。
echo "<script>parent.$.fn.colorbox.close(); </script>";
$this->redirect(array('site/index'));
您在屏幕上回显某些内容,然后重定向,这是不可能的。 您要做的是重定向而不回显任何内容。 之后,您需要确保颜色框不会再次打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.