0

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")')),
    ),
));
?>
Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100
  • This is not really related to Yii, when tried google had this answer instantly: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab –  Jul 10 '13 at 08:45
  • @PeterM op has already used the correct code to open in new window – bool.dev Jul 10 '13 at 08:55

2 Answers2

3

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.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
0

Change your url property From

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

To

   'url' => array('#'),
Hearaman
  • 8,466
  • 13
  • 41
  • 58