• 29-12-2007, 21:28:49
    #1
    Çok sağlam bir kod. Bunun çalışan versiyonunu bulmak çok zordur.
    ArÅŸivinize koyun arkadaÅŸlar.
    Kod ne işe yarıyor.

    Diyelim ki div ile açılır kapanır menüler yaptınız. Ziyaretçi menüyü kapattı. Bir dahaki ziyaretinde yada alt sayfalardan ana sayfaya geldiğinde bir daha göstertmiyor kapattığı bölüm menüleri.
    Kodu çalıştırınca anlarsınız zaten olayı




    <script type="text/javascript">
    
    // The Cookie Jar
    ////// Standard functions for Setting, Getting, and Deleting Cookies
    ////// john@xcentrixlc.com
    
    // To set a cookie pass in the name, value, and persist type
    // SetCookie("name", "value", 1) set the persist type to 1 to store your cookie
    // or to 0 to last for this browser session only. By default the storage time is for one year.
    // You can add another argument to hold the length of time you want to store the cookie:
    // SetCookie("name", "value",1,15768000000) would store the cookie for 6 months.
    // the time is calcutaled in miliseconds so for one month of milliseconds you calculate:
    // 31 * 24 * 60 * 60 * 1000=2678400000
    // To get or delete a cookie simply pass in the name of the cookie you want to effect
    // GetCookie("name") DeleteCookie("name")
    // if you ask for a cookie that does not exist it will return null.
    
    function getCookieVal(offset) {
    endstr = document.cookie.indexOf (";", offset)
    if(endstr == -1) endstr = document.cookie.length
    return unescape(document.cookie.substring(offset, endstr))
    }
    
    function GetCookie(name) {
    arg = name + "="
    alen = arg.length
    clen = document.cookie.length
    var i = 0
    while (i < clen) {
    j = i + alen
    if(document.cookie.substring(i, j) == arg) return getCookieVal(j)
    i = document.cookie.indexOf(" ", i) + 1
    if(i == 0) break
    }
    return null
    }
    
    function SetCookie (name, value, per, exp) {
    cstr = name + "=" + escape(value) + ";"
    if(per){
    addtime=(exp>0) ? exp : 31536000000
    expdate = new Date()
    expdate.setTime(expdate.getTime() + addtime)
    expdate = expdate.toGMTString()
    cstr+=" expires=" + expdate
    }
    document.cookie = cstr
    }
    
    function DeleteCookie(name) {
    exp = new Date()
    exp.setTime (exp.getTime() - 1)
    cval = GetCookie(name)
    if(cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()
    }
    
    function expandCollapse(id,img){
    var div = document.getElementById(id);
    if (div.style.display=='none'){
    div.style.display='block';
    document.images[img].src='cmdCollapse.gif';
    SetCookie(id,'block');
    }
    else {
    div.style.display='none';
    document.images[img].src='cmdExpand.gif';
    SetCookie(id,'none');
    }
    }
    
    function setDisplay(div,disp){
    if (disp!=null) div.style.display=disp; 
    }
    
    function setState(){
    var div;
    var i=1;
    while (div=document.getElementById('Div'+(i++))) {
    setDisplay(div,GetCookie(div.id));
    }
    while (div=document.getElementById('Img'+(i++))) {
    setDisplay(div,GetCookie(div.id));
    }
    }
    
    window.onload = setState;
    </script>
    </head>
    <body >
    
    <a href="#" onclick="expandCollapse('Div1','Img1')"><img src="cmdCollapse.gif" id="Img1" alt="" /><span>DIV 1 title</span></a>
    <div id ="Div1" style="display:block;" class="Content">Div1 content<br />blah<br />blah<br />blah<br />blah<br />blah<br />blah<br /></div>
    
    
    <br /><br />
    
    <a href="#" onclick="expandCollapse('Div2','Img2')">
    <img src="cmdExpand.gif" id="Img2" alt="" width="28" height="28" /><span >DIV 2 title</span></a>
    <div id ="Div2" style="display:none;" class="Content">Div2 content<br />blah<br />blah<br />blah<br />blah<br />blah<br />blah<br />
    </div>
    
    
    </body>
    </html>
  • 29-12-2007, 21:36:05
    #2
    Üyeliği durduruldu
    TÅŸk.ler baya bir iÅŸe yarayacak
  • 05-02-2009, 03:37:58
    #3
    çok işime yaradı.
    saygı duyuyorum.
  • 05-02-2009, 03:44:40
    #4
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Güzel kod teşekkürler radmin abi
    Bunu yer değiştiren div'lere uyarlıyarak iGoogle gibi sayfalar'da yaratabiliriz sanırım.
  • 05-02-2009, 07:49:56
    #5
    Ben bunu js reklamlarda kullanmayı düşündüm. Reklam divini kapayınca ikinci ziyarette div yine kapalı konumda olur diyerek. Herşey tamam fakat bu cookie süresini 1 gün yapmam lazım. addtime=(exp>0) ? exp : 31536000000 satırını oynadım birşey değişmedi. Bilen duyan gören var mı?
  • 05-02-2009, 08:29:38
    #6
    Radmin 'in 2 Yaşındaki Konularından biri...