2012-03-15 47 views
0

我的網站現在在主頁上運行javascript彈出,現在我想在用戶點擊主頁時執行操作,用戶將進入主頁並且javascript彈出窗口會顯示,但點擊關閉後,用戶再次點擊主頁這個JavaScript不會運行,這個腳本只有一天活動。在javascript中設置cookie - 彈出集成

那麼,如何將cookies與我的javascript結合起來呢?

* 這個彈出運行完美,但只剩餅乾腳本

網址http://tsubamecorp.com/home/index.php?route=extras/blog/getblogcategory&blogpath=41

這是我的JavaScript彈出:

<script> 

    var $xx = jQuery.noConflict(); 

    $xx(document).ready(function() { 

    //select all the a tag with name equal to modal 
    $xx('a[name=modal]').click(function(e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     //Get the A tag 
     var id = $xx(this).attr('href'); 

     //Get the screen height and width 
     var maskHeight = $xx(document).height(); 
     var maskWidth = $xx(window).width(); 

     //Set heigth and width to mask to fill up the whole screen 
     $xx('#mask').css({'width':maskWidth,'height':maskHeight}); 

     //transition effect  
     $xx('#mask').fadeIn(1000); 
     $xx('#mask').fadeTo("slow",0.90); 

     //Get the window height and width 
     var winH = $xx(window).height(); 
     var winW = $xx(window).width(); 

     //Set the popup window to center 
     $xx(id).css('top', winH/2-$xx(id).height()/1); 
     $xx(id).css('left', winW/2-$xx(id).width()/2); 

     //transition effect 
     $xx(id).fadeIn(1000); 

    }); 

    //if close button is clicked 
    $xx('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $xx('#mask').hide(); 
     $xx('.window').hide(); 
    });    

}); 
</script> 
<script type="text/javascript"> 
window.onload = function() { $xx('a[href="#dialog1"]:eq(0)').click(); 
} 
</script> 
+0

不太清楚你的問題:「這個劇本只活躍了一天」,你的意思是在一天之內,每個用戶都可以看到一次的彈出窗口,而另一一天到來,會再次看到它? – 2012-03-15 04:23:47

+0

你在說什麼cookie。請更清楚地解釋你的問題,標題有點誤導。您想在點擊一次後禁用彈出窗口嗎? – specialscope 2012-03-15 04:24:03

+0

是的..只有24小時 – ruslyrossi 2012-03-15 04:24:37

回答

0

這樣的事情。一個cookie的過期意味着該cookie將被sys刪除的時間。谷歌一些的document.cookie

Cookie = { 
    get:function (key) { 
     var ret = this.toObj()[key]; 
     if(ret === undefined){ 
      return ret; 
     } 
     return unescape (this.toObj()[key]); 
    }, 
    set:function (key, value, expires) { 
     if (expires){ 
      var exdata = new Date(); 
      exdata = exdata.setDate (exdata.setDate() + expires).toGMTString(); 
     } 
     document.cookie = key+"="+escape(value) + (exdata ? "; expires= " + exdata : ""); 
    }, 
    remove:function (key) { 
     document.cookie = key+"=remove;expires="+(new Date).toGMTString(); 
    }, 
    toJSON:function () { 
     return JSON.stringify(this.toObj); 
    }, 
    toObj:function () { 
     var ret={}, cookiearr = document.cookie.split(";"); 
     var i, start, key, value; 
     for (i = 0; l = cookiearr[ i++ ];) { 
      start = l.indexOf ("="); 
      ret [ l.slice(0, start) ] = l.slice (start+1); 
     } 
     return ret; 
    } 
} 
+0

好的..謝謝..我會嘗試 – ruslyrossi 2012-03-15 04:58:54