문제

Hi all creating a link that when you click it, it opens a new window. I was wondering if it's possible to restrict the size of the window opening?

this is the code I have for the link that opens the window

<?php echo $this->Html->link(
    $this->Html->image($help, array(
    "alt" => "eBox")),
    '/accounts/help', array('target'=>'_blank', 'escape'=>false)); ?>
도움이 되었습니까?

해결책

You can do this, but only with Javascript.

Raw code would be something like:

<a href="/pages/home" target="_blank" onClick="window.open('/pages/home', 'windowname','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=290'); return false;">Text Link</a>

The only parameters you really need are width and height, but you might find the others useful too. If not, just delete them. If the user doesn't have javascript, it'll just open the link normally.

To do it with html helper, pass your javascript through to the onClick array key:

<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array(
    'target'=>'_blank',
    'escape'=>false,
    'onClick'=>"window.open('/pages/home', 'windowname','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=290'); return false;"
)); ?>

PS - you can read up on the window.open method here: http://www.w3schools.com/jsref/met_win_open.asp

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top