Question

Has anyone tryed to set a CMenu link to open in a new window?

Mine, opens the new window, as blank page and still goes to the requested url

<?php
$this->widget('zii.widgets.CMenu', array(
    'items' => array(
        array('label' => Yii::t('admin', 'Live Reports'), 'url' => array('/admin/liveReports/index'), 'visible' => !Yii::app()->user->isGuest, 'active' => ($this->id == 'liveReports'), 'linkOptions' => array('onclick' => 'javascript:window.open("/admin/liveReports/index","x","width=200,height=100")')),
    ),
));
?>
Was it helpful?

Solution

You forgot to return false; from the onclick attribute, which is why the current window/tab still navigates to the url:

'linkOptions' => array(
    'onclick' => 'javascript:window.open("/admin/liveReports/index","x","width=200,height=100"); return false;'
)

Consider using an onclick event handler instead, for good practice, i.e Unobtrusive Javascript.

OTHER TIPS

Change your url property From

   'url' => array('/admin/liveReports/index'),

To

   'url' => array('#'),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top