Js Ad Script

Discussion in 'JavaScript' started by laffin, Nov 28, 2007.

  1. #1
    Hy again ...

    Sorry i am new and i post wrong there: http://forums.digitalpoint.com/showthread.php?t=577015

    I have a problem ...

    I found yesterday this ad script, very nice, http://dynamicdrive.com/dynamicindex17/stickynote.htm

    But there ads appear after any refresh ...
    I want, if i see the ad one time, next time when appear, after 24 hours ...
    I think is possible whit cookies, but i don`t know how

    Anyone can help me please ?

    Thank you guys!
    laffin
     
    laffin, Nov 28, 2007 IP
  2. hrcerqueira

    hrcerqueira Peon

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello, check this functions:

    
    function setCookie(name,value,expires, options) {
       if (options===undefined) { options = {}; }
       if ( expires ) {
          var expires_date = new Date();
          expires_date.setDate(expires_date.getDate() + expires)
       }
       document.cookie = name+'='+escape( value ) +
          ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + 
          ( ( options.path ) ? ';path=' + options.path : '' ) +
          ( ( options.domain ) ? ';domain=' + options.domain : '' ) +
          ( ( options.secure ) ? ';secure' : '' );
    }
    
    function getCookie( name ) {
       var start = document.cookie.indexOf( name + "=" );
       var len = start + name.length + 1;
       if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
          return null;
       }
       if ( start == -1 ) return null;
       var end = document.cookie.indexOf( ';', len );
       if ( end == -1 ) end = document.cookie.length;
       return unescape( document.cookie.substring( len, end ) );
    }
    
    Code (markup):
    After add is shown:

    setCookie('addShown','true', 1);

    Before add is shown:


    if (getCookie('addShown'))
    //show add


    It should be easy to set up. Just remember to set the expiration to one day.

    Cheers
     
    hrcerqueira, Nov 29, 2007 IP