문제

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")')),
    ),
));
?>
도움이 되었습니까?

해결책

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.

다른 팁

Change your url property From

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

To

   'url' => array('#'),
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top