Question

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)); ?>
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top