SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disclaimer Page Cookies

    I found a disclaimer script from the web and installed on my site, I am newbie to javascipt, and hope someone could help.

    How can I modify the script so that every time a user close the browser windows and visit the site, they need to accept the disclaimer again??

    Thanks a lot for your suggestion in advance.

    Code:
    <script type='text/javascript' >
    // Disclaimer DHTML
    // Copyright Outils.XXX 2012
    
    function ScanCookie(variable)
    {
     cook=document.cookie;
     variable+="=";
     place=cook.indexOf(variable,0);
      if(place<=-1) return("0");
     else
     {
      end=cook.indexOf(";",place)
      if(end<=-1) return(unescape(cook.substring(place+variable.length,cook.length)));
      else return(unescape(cook.substring(place+variable.length,end)));
     }
    }
    
    function Entrer()
    {
     document.cookie="disclaimerok=oui;path=/;";
     if(document.getElementById) document.getElementById("disclaimer").style.display='none'
     top.location.href=location.href;
    }
    
    if(ScanCookie("disclaimerok")==0)
    {
     document.write(""
     +"<style type=\"text/css\">"
     +"<!--"
     +"object{ visibility:hidden; }"
     +"#disclaimer{ text-align:left; }"
     +"#disclaimer-fond{ position:absolute; z-index:15000; width:100%; height:2000px; background:#fff; text-align:center; line-height:normal; clear:both; filter:alpha(opacity=95); -moz-opacity:0.95; opacity:0.95; }"
     +"#disclaimer-conteneur{ position:absolute; z-index:15001; width:100%; text-align:center; clear:both; }"
     +"#disclaimer-cadre{ width:718px; padding:10px; margin:150px auto 0 auto; text-align:left; background:#fff; border:#ddd 1px solid; }"
     +"#disclaimer-cadre b{ display:block; padding:10px 0 10px 0; text-align:center; font-size:21px; color:#666666; }"
     +"#disclaimer-cadre font{ display:block; padding:10px 0 20px 0; text-align:center; font-size:21px; color:#666666; }"
     +"#disclaimer-cadre p{ margin:0; padding:10px; font-size:16px; color:#666666; }"
     +"#disclaimer-cadre .boutons{ margin:0; padding:10px; text-align:center; }"
     +"#disclaimer-cadre a{ text-decoration:none; font-size:36px; font-weight:bold; color:#6D28AA; }"
     +"#disclaimer-cadre a:hover{ text-decoration:underline; }"
     +"-->"
     +"<\/style>"
     +"<div id='disclaimer'><div id='disclaimer-fond'></div><div id='disclaimer-conteneur'>"
     +"<div id='disclaimer-cadre'>"
     +"<b>Site Disclaimer</b>"
     +"<p>Message here</p>"
     +"<div class='boutons'><a href='#' onclick='Entrer(); return(false)'>Accept</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a rel='nofollow' href='http://www.google.com/'>Leave</a></div>"
     +"</div>"
     +"</div></div>"
     );
    }
    </script>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by desmondok View Post
    How can I modify the script so that every time a user close the browser windows and visit the site, they need to accept the disclaimer again??
    Normally if a cookie is set without an expires time/date, the cookie will expire at the end of the session. That is, when the user closes their browser windows.

    I don't see an expires time being used with your script, so it seems at first glance as if things are already working the way that you want them to be.
    However, since you are posting this, something clearly isn't going according to plan.

    Does it not show again when the web browser is closed and then opened again?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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