Insert Cookie value into hyperlink.

Posted on 2006-05-17
Last Modified: 2008-03-10
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;
            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;
      document.cookie = "thePath="+cookieData+";expires="+expireDate.toGMTString();
      alert("set cookie: "+document.cookie);

function readCookie(){ // reads a 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();
      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>
Question by:buddy9462
    LVL 63

    Accepted Solution

    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.

    LVL 63

    Expert Comment

    You are welcome.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now