2012-07-04 64 views
0

我的程序的目的是用JQuery打开一个colorbox,点击一个链接。如何在没有任何点击的情况下自动启动colorbox?

下面的代码:

<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> 

此代码的工作非常完美。

现在由于其他原因,我需要在没有任何点击的情况下自动打开带有特殊条件的彩盒。我试着用下面的代码,但我不能访问我的控制器:

<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> 

的代码$.colorbox行似乎是一件好事,因为当我刷新颜色框被打开,但没有其内容的页面。为了与控制器建立链接,我尝试使用document以下代码行,但它在另一个页面中打开了正确的视图内容,但没有打开到colorbox中。

有人能帮助我吗?预先感谢您的回答。

回答

1

href选项像

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

这行

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

呼叫颜色框会重定向到该网页,则不会加载到颜色框,以便删除。

阅读更多关于href选项。

+0

谢谢我在同一时间找到了解决方案。祝你有美好的一天。再见 – user1450730

相关问题