Search code examples
phpyiiwindow.openyii1.xcjuidialog

window.open not work inside cjuidialog yii1


i want open new tab after save in cjuidialog. i used

window.top.location.href

its work but not open new tab but if i used

window.open('https://api.whatsapp.com/send?phone=+62878787811423&text=Tesdawks', '_blank');

it doesnt work. this my full code

<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id'=>'cru-dialog',
        'options'=>array(
            'title'=>'Detail view',
            'autoOpen'=>false,
            'modal'=>true,
            'width'=>'80%',
            'height'=>450,
            'close'=>'js:function(){
                $("#cru-frame").attr("src","");
                $.fn.yiiGridView.update("indexKonsumen-grid", {
                    data: $(this).serialize()
                });
            }',
        ),
    ));
?>

<iframe id="cru-frame" width="100%" height="100%"></iframe>
<?php $this->endWidget(); ?>

my controller

if(isset($_POST['wa'])){
                    echo CHtml::script("window.parent.$('#cru-dialog').dialog('close');
                                        window.parent.$('#cru-frame').attr('src','');
                                        window.open('https://api.whatsapp.com/send?phone=+62878787811423&text=Tesdawks', '_blank');
                    ");
}

Solution

  • The second parameter for window.open() is the windowName, you appear to be using it in the context of trying to open a new tab by providing a target as _blank, however the default behaviour for window.open is to open the window in a new tab, so this is redundant.

    if(isset($_POST['wa'])) {
        echo CHtml::script("window.parent.$('#cru-dialog').dialog('close');
        window.parent.$('#cru-frame').attr('src','');
        window.open('https://api.whatsapp.com/send?phone=+62878787811423&text=Tesdawks');
    ");
    }