2012-07-25 49 views
0

如何让我的colorbox在查询字符串存在时自动显示。 到目前为止,我有以下几点:jquery colorbox在页面启动时自动显示

$(document).ready(function() 
{ 
    //if this is coming from continental 
    if (document.location.href.indexOf("redirect=cfs") != -1) 
    { 
     //create box 
     var $notice = $("<div>hello World</div>").appendTo($("body")); 
     console.log($notice.text()); 
     $notice.colorbox({ inline: true, width: "965px" }); 
    } 
}); 

但是,这并没有帮助,因为它似乎是你有点需要触发颜色框显示的东西吗?

编辑: 我才意识到,你可以使用$.colorbox,但我如何得到我的内容到它?

问候, 雅克

回答

0

下面的代码为我做:

$(document).ready(function() 
{ 
    //if this is coming from continental 
    if (document.location.href.indexOf("redirect=cfs") != -1) 
    { 
     //create box 
     var $notice = $("<div id='partnerMove'>test</div>").appendTo($("body")); 
     console.log($notice.text()); 
     **$.colorbox({ href: '#partnerMove', inline: true, width: "600px" });** 
    } 
}); 

所以,你可以动态创建一个HTML元素,然后使用$.colorbox参考使用颜色框的HREF设置的新元素。

1

只要使用颜色框的html属性:

$(document).ready(function(){ 
    if (document.location.href.indexOf("redirect=cfs") != -1) 
    { 
     var $notice = $("<div>hello World</div>"); 
     $notice.colorbox({ html: $notice, width: "965px" }); 
    } 
});