0

The purpose of my program is to open a colorbox with JQuery clicking on a link.

Here's the code :

<a href="<?= $html->url(array('controller' => 'competitions', 'action' => 'index')) ?>" class="game-popup">
    <?= $this->Html->image('image-link.jpg') ?>
</a>
<script type="text/javascript">
$(document).ready(function(){
  $('.game-popup').colorbox({'iframe':true, 'width':'690px', 'height':'670px'});
});
</script>

This code works perfectly.

Now for an other reason I need to open a colorbox automatically with a special condition without any click. I tried with the code below but I can't access to my controller:

<a href="<?= $html->url(array('controller' => 'competitions', 'action' => 'index')) ?>" class="game-popup">
    <?= $this->Html->image('competition-galaxy-s3.jpg') ?>
</a>
<script type="text/javascript">
$(document).ready(function(){
  $.colorbox({'iframe':true, 'width':'690px', 'height':'670px'});
  document.location.href="/ArgusDuMobile/competitions/index";
});
</script>

The line of code with $.colorbox seems to be good because when I refresh the page the colorbox is being opened but without its content. To do the link with the controller I tried the following line of code with document but it open the correct content of the view in an other page but not into the colorbox.

Does anyone could help me? Thanks in advance for your answer.

0

1 Answer 1

1

Call colorbox with href option like

$.colorbox({ href: '/ArgusDuMobile/competitions/index',
            'iframe':true, 'width':'690px', 'height':'670px'});

and this line

document.location.href="/ArgusDuMobile/competitions/index";

Will redirect to that page wont load that into colorbox so remove that.

Read more on href option.

1
  • thanks I found the solution in the same time. Have a good day. Bye Jul 4, 2012 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.