popup once

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivapradeep
    New Member
    • Mar 2008
    • 1

    popup once

    Hi

    i have a popup which appears once when the page is opened and then the cookie is deleted on the no of days mentioned, but here i need to change it on the session basis, i;e when the page is closed event the cookie as to be deleted. Below is what the code i have been using. Please help me out on this.

    Thanking You,
    Regards,
    Shiv.


    [CODE=javascript]var expDays = 1; // number of days the cookie should last

    var page = "Popup.html ";
    var windowprops = "width=345,heig ht=335,location =no,left=180,to p=300,toolbar=n o,menubar=no,sc rollbars=no,res izable=yes";

    function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie .length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cooki e.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie .indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }

    function SetCookie (name, value) {
    var argv = SetCookie.argum ents;
    var argc = SetCookie.argum ents.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTSt ring())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

    function DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString ();
    }

    var exp = new Date();
    exp.setTime(exp .getTime() + (expDays*24*60* 60*1000));

    function amt(){
    var count = GetCookie('coun t')
    if(count == null) {
    SetCookie('coun t','1')
    return 1
    } else {
    var newcount = parseInt(count) + 1;
    DeleteCookie('c ount')
    SetCookie('coun t',newcount,exp )
    return count
    }
    }

    function getCookieVal(of fset) {
    var endstr = document.cookie .indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie .length;
    return unescape(docume nt.cookie.subst ring(offset, endstr));
    }

    function checkCount() {
    var count = GetCookie('coun t');
    if (count == null) {
    count=1;
    SetCookie('coun t', count, exp);
    window.open(pag e, "", windowprops);
    } else {
    count++;
    SetCookie('coun t', count, exp);
    }
    }

    window.onload=c heckCount;[/CODE]
    Last edited by gits; Mar 10 '08, 12:40 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Call DeleteCookie() onunload.

    Comment

    Working...