2012-08-28 89 views
0

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

但它不起作用。

任何帮助将不胜感激。

回答

0

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

所以你可以这样写:

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

这是记录在这里: http://www.jacklmoore.com/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>