我想在我的博客的主页上显示灯箱。但它出现在每个页面上

时间:2012-01-16 15:29:38

标签: jquery html lightbox

我有这段代码:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js'/>

     <script src='https://gj37765.googlecode.com/svn/trunk/html/[www.gj37765.blogspot.com]jquery.colorbox-min.js'/>
 <link href='https://gj37765.googlecode.com/svn/trunk/html/%5Bwww.gj37765.blogspot.com%5Dfbpopup.css' rel='stylesheet' type='text/css'/>
 <script type='text/javascript'>
     jQuery(document).ready(function(){
        if (document.cookie.indexOf(&#39;visited=flase&#39;) == -1) {
            var fifteenDays = 1000*60*60*24*30;
            var expires = new Date((new Date()).valueOf() + fifteenDays);
            document.cookie = &quot;visited=false;expires=&quot; + expires.toUTCString();
        $.colorbox({width:&quot;400px&quot;, inline:true, href:&quot;#mdfb&quot;});
            }
     });
     </script>

该代码适用于类似Facebook的框,当用户访问我的博客时会显示该框。我的博客是博主。我的问题是,每当用户看到其他帖子或刷新页面时,此jquery的灯箱会一次又一次出现。我希望它只出现在网站的主页上。我对jQuery一无所知。

2 个答案:

答案 0 :(得分:1)

将“false”替换为“true”

if (document.cookie.indexOf('visited=false') == -1) {

还有一个

document.cookie = 'visited=false; expires=' + expires.toUTCString();

答案 1 :(得分:0)

您只需查看顶部地址链接并进行比较即可...

<script>
 if(window.location.href=="www.example.com"){
   // do the reset of your code here....
   jQuery(document).ready(function(){
    if (document.cookie.indexOf('visited=flase') == -1) {
        var fifteenDays = 1000*60*60*24*30;
        var expires = new Date((new Date()).valueOf() + fifteenDays);
        document.cookie = 'visited=false;expires=' + expires.toUTCString();
    $.colorbox({width'400px', inline:true, href:'#mdfb'});
        }
   });
 }
</script>

复制并粘贴上述内容,并将example.com替换为您的域名,例如“myid.blogspot.com”或者blogspot工作:)