0

私のプログラムの目的は、JQuery でリンクをクリックしてカラーボックスを開くことです。

コードは次のとおりです。

<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が、ビューの正しいコンテンツを別のページで開きますが、カラーボックスには開きません。

誰でも私を助けることができますか?ご回答ありがとうございます。

4

1 に答える 1

1

href次のようなオプションでカラーボックスを呼び出す

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

そしてこの行

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

そのページにリダイレクトされますが、それはカラーボックスにロードされないため、削除します。

hrefオプションの詳細をご覧ください。

于 2012-07-04T08:32:24.900 に答える