Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Insert Cookie value into hyperlink.

Posted on 2006-05-17
2
Medium Priority
?
369 Views
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;
            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>
0
Comment
Question by:buddy9462
  • 2
2 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 16704188
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 16725511
You are welcome.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

569 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