popup with cookies... need to fix

Discussion in 'JavaScript' started by motiejus, May 13, 2008.

  1. #1
    Hi, I have a simple html website and I want that music would play in it. I decided to use a JS popup window. But I have one problem with my script. It has cookies with session:

    
    <script type="text/javascript">
    var popurls=new Array()
    
    popurls[0]="music/dance.html"
    popurls[1]="music/dj.html"
    popurls[2]="music/hiphop.html"
    
    function openpopup(popurl){
    var winpops=window.open(popurl,"","width=370,height=10")
    }
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    function loadornot(){
    if (get_cookie('jkpopup')==''){
    openpopup(popurls[Math.floor(Math.random()*(popurls.length))])
    document.cookie="jkpopup=yes"
    }
    }
    loadornot()
    </script>
    
    Code (markup):
    So, when the popup is loading it's ok. When I am going through pages which have the same popup link, the popup is not refreshing, which is also good. But when popup has a different link (for example "hiphop.html") it is not refreshing.

    Is it possible to make a different link to work in this popup?
     
    motiejus, May 13, 2008 IP