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 3 of 3
  1. #1
    mex
    mex is offline
    Regular Coder
    Join Date
    Jul 2003
    Location
    somewhere
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with cookie

    Can anyone help me out with this script so that it does NOT ask or popup every time the page loads....

    <SCRIPT language="JavaScript">
    <!--
    var yourname= prompt('Do enter your name for a proper welcome :', ' ');
    if ( (yourname==' ') || (yourname==null) )
    {
    yourname="mex";
    }
    //-->
    </SCRIPT>

    Pliz make the script as small as possible and also if possible to reset itself after an hour or so as 24 hrs is a bit too long!
    Wonder

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:
    Code:
    <script type="text/javascript">
    <!--//
    
     function doWelcome() {
       var dc = document.cookie;
         if(dc.length > 0) {
            document.getElementById('welcome').innerHTML = 'Welcome back '+ dc;
         }
    
         if(dc.length == 0) {
            var yourname = prompt('Do enter your name for a proper welcome :', ''); 
              if (yourname == '' || yourname == 'null') {yourname = 'mex';}
              else {yourname = yourname;}
                document.getElementById('welcome').innerHTML = 'Welcome '+ yourname;
                var today = new Date();
                today.setTime(today.getTime() + 1*60*60*1000);
                var expString = "; expires=" + today.toGMTString();
                document.cookie = yourname + expString;
          }
    
     }
     window.onload = doWelcome;
    //-->
    </script>
    </HEAD>
    
    <BODY>
    <span id="welcome"></span>
    Change 1 to reflect the number of hours to set the cookie.

    ....Willy

  • #3
    mex
    mex is offline
    Regular Coder
    Join Date
    Jul 2003
    Location
    somewhere
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx so much for the help.
    Wonder


  •  

    Posting Permissions

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