Insert Cookie value into hyperlink.

First let me say I'm no expert with javascript. Resources like this may me look much better than I am. That said,

I have the following function which:

User selects a webcase (This is where the cookie is written. That works)
Is taken to a form page to capture information
Upon submission is redirected to a thank you page where they get a "Click Here" hyperlink of the webcast they chose.

The probelm is when they get to the thank you page, the hyperlink does not capture the cookie value.

Here's the javascipt:


function setCookie(cookieData){ // sets a cookie to store the path to the requested archived webcast
      if (document.cookie !=""){ // first, delete all the cookies
            thisCookie = document.cookie.split(";");
            expireDate = new Date;
            expireDate.setYear(expireDate.getYear()-1);
            for (i=0; i<thisCookie.length; i++){
                  cookieName = thisCookie[i].split("=")[0];
                  document.cookie = cookieName+"=;expires="+expireDate.toGMTString();
            }
      alert(thisCookie.length+" cookies deleted");
      }
      expireDate = new Date;
      expireDate.setYear(expireDate.getYear()+1);
      document.cookie = "thePath="+cookieData+";expires="+expireDate.toGMTString();
      alert("set cookie: "+document.cookie);
}

function readCookie(){ // reads a cookie
alert("cookie="+document.cookie);
      if (document.cookie != ""){
            return document.cookie.split("=")[1];
      }
}
function playMedia(){ // reads the stored path to the recorded webcast and plays it in a popup window
      var thePath = readCookie();
      alert(thePath);
      theWindow = NewWindow(thePath, 'videohi','800','688','no');
}

function playWebcast(thePath){
      theWindow = NewWindow(thePath, 'videohi','800','688','no');
}

function clearInput(id) {
      field = document.getElementById(id);
      field.value = "";
}


Any ideas. All I get in the hyperlink is: <a href="javascript:playMedia();">here</a>
buddy9462Asked:
Who is Participating?
 
ZvonkoSystems architectCommented:
Extend this line in setCookie() function:
 document.cookie = "thePath="+cookieData+";expires="+expireDate.toGMTString();

To this:
 document.cookie = "thePath="+cookieData+"; path=/; expires="+expireDate.toGMTString();

Also be aware that cookies work ONLY inside same internet domain. If different servers in different domains or even without domain suffix in the url, then it will not work because of cross domain access restrictions.

0
 
ZvonkoSystems architectCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.