Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    :: help with cookies ::

    Hi peeps

    im after the following:

    : check for a cookie to see if this page has been accessed b4
    : if yes do nothing
    : if no should popup a page & create a cookie to show this process doesnt need doing again..

    does that make sense? im not with it today!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    How about a "pop once" script


    <SCRIPT language=JavaScript>
    <!--
    cookie_name="poponce"
    expDays = 365; // number of days the cookie should last

    function get_cookie (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.cookie.substring(i, j) == arg)
    return get_cookie_val (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }

    function get_cookie_val(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

    function set_cookie (name, value,expires) {
    var argv = set_cookie.arguments;
    var argc = set_cookie.arguments.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.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

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

    function checkCount() {
    var count = get_cookie('poponce');
    if (count == null) {
    count=1;
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
    set_cookie('poponce', count, exp);

    dothis()
    }
    }

    function dothis(){
    var windowprops = "left=50,top=150,width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no"; window.open("page.htm", "", windowprops);
    }
    // -->
    </SCRIPT>


    <BODY OnLoad="checkCount()">
    Last edited by Mr J; 08-05-2004 at 06:42 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    cheers m8e! works a treat!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *points* Babel's making popups! Haha, just kidding.

    I typically use PHP to handly any cookie work, mainly because I've never bothered leanring how to handle JS cookies... Might just study this script Thanks.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    hmmm dont have php here at work... just lotus domino servers...

    i had to not use that popup script fully in the end as so many people have popup blockers here at work! i just use an ammended version of the above to refer to another page now
    Last edited by babelfish; 08-09-2004 at 10:12 AM.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •