【问题标题】:Automatic open Colorbox modal window自动打开 Colorbox 模态窗口
【发布时间】:2012-08-29 12:37:14
【问题描述】:

我在 Drupal 7 中使用 Colorbox 模块。我正在打开一个外部网站。我可以通过链接使其工作。单击here,然后单击底部中间列的“颜色框弹出”链接。客户端希望在页面打开时自动打开。我创建了一个块并添加了以下代码(来自 colorbox 站点)。

<script type="text/javascript">
// Display a welcome message on first visit, and set a cookie that expires in 30 days:
if (document.cookie.indexOf('visited=true') === -1) {
    var expires = new Date();
    expires.setDate(expires.getDate()+30);
    document.cookie = "visited=true; expires="+expires.toUTCString();
    jQuery.colorbox({html:"URL goes here", width:887, height:638});
}
</script>

但它不起作用。

任何帮助将不胜感激。

【问题讨论】:

    标签: drupal-7 colorbox


    【解决方案1】:

    你需要等到 DOM 准备好:

    <script type="text/javascript">
    $(document).ready(function(){
    // Display a welcome message on first visit, and set a cookie that expires in 30 days:
    if (document.cookie.indexOf('visited=true') === -1) {
        var expires = new Date();
        expires.setDate(expires.getDate()+30);
        document.cookie = "visited=true; expires="+expires.toUTCString();
        jQuery.colorbox({href:"URL goes here", width:887, height:638});
    }
    });
    </script>
    

    【讨论】:

      【解决方案2】:

      您需要将 open 参数设置为 true

      所以你可以写:

      jQuery.colorbox({href:"URL goes here", width:887, height:638, open: true});
      

      这在此处记录: http://www.jacklmoore.com/colorbox

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-17
        • 1970-01-01
        • 2014-04-12
        • 1970-01-01
        • 1970-01-01
        • 2018-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多