0

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');
                    ");
}
niac
  • 33
  • 2
  • 17
  • Have you tried just `window.open('https://api.whatsapp.com/send?phone=+6287878711423&text=Tesdawks')` without including the `_blank` target? Does this create any redirect? – Skully Jul 20 '20 at 04:21
  • wow you saved my life @Skully . remove `_blank` and 100% work. Thank you – irfan syamsuri Jul 20 '20 at 06:27
  • Glad it solved it, I have posted an answer with some more clarification for anyone else who might stumble upon this issue :) – Skully Jul 20 '20 at 18:17

1 Answers1

1

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');
");
}
Skully
  • 2,882
  • 3
  • 20
  • 31