自动打开Colorbox模态窗口

时间:2012-08-28 18:50:08

标签: drupal-7 colorbox

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

但它不起作用。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

您需要将打开参数设置为 true

所以你可以写:

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

这里有记录: http://www.jacklmoore.com/colorbox

相关问题