Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I add cookie values to a querystring

Posted on 2009-06-30
32
Medium Priority
?
288 Views
Last Modified: 2012-05-07
I was givinen a cople of code nippets at work that I have to put in place so that when a user clicks on a link that will be inside an email it will redirectem to a page with all the values of the cookie attached to the querystring.

I have NO IDEA how to do this. I've spend hours in google already today and not getting anywhere.

I'm trying to test first, so basically I will like to see a HTML file with set SetCookie function and a hyperlink and once you click on this particular link it will take you to another HTML page with all the values of the cookie added to the querystring.

I"M assuming that some sort of FORM is needed wiht hidden values to fill the values of the cookie, but have no idea how to accomplish this.

Please any help is going to be very very very appreciated!
thanks,

HERE IS AN EXAMPLE OF HOW THE URL SHOULD LOOK LIKE:
Example URL:


http://blah.stores.yahoo.net/tholap.html?j=1018883&e=bloah.blah@blah.com&l=166265_HTML&u=10424764&mid=103148&jb=0


Variables:

j = JobID
e = EmailAddr
l = ListID
u = UrlID
mid = MemberID
jb = JobID

//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
				case "e":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("EmailAddr",e,ExpireDays);
					break;
				case "j":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("JobID",j,ExpireDays);
					break;
				case "l":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("ListID",l,ExpireDays);
					break;
				case "jb":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("BatchID",jb,ExpireDays);
					break;
				case "u":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("UrlID",u,ExpireDays);
					break;
				case "mid":
					thevars[i] = thevars[i].replace("=","='")+"'";
					eval(thevars[i]);
					SetCookie("MemberID",mid,ExpireDays);
					break;
				default:
					eval(thevars[i]);
					break;
			}
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
	if(document.cookie.length >0) {
		startC = document.cookie.indexOf(cookiename+"=");
		if (startC != -1) {
			startC += cookiename.length+1;
			endC = document.cookie.indexOf(";",startC);
			if(endC ==-1) endC = document.cookie.length;
				return unescape(document.cookie.substring(startC, endC));
				}
			}
		return null;
	}
	
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>

Open in new window

0
Comment
Question by:vthunder70
  • 22
  • 10
32 Comments
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747425
0
 

Author Comment

by:vthunder70
ID: 24747482
I guess the problem is that I don't knwo how to get the HTML to work with the javascript given to me.

The Javascript part is done the problem is making work together.
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747587
Ok, so you're setting and retrieving a cookie properly.  Now, what do you want the HTML to do?  You want to send the user to another page?

Once you grab the cookie value, you can write it to a hidden input.

<input type="hidden" name="myCookieValue" id="myCookieValue" value="cookieValueGoesHere" />

Then, yes, you will need a form to send the user somewhere else.  I would use a GET method, so the form elements appear in the querystring.
0
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!

 

Author Comment

by:vthunder70
ID: 24747656
Yes jmanGHJS97,

I imagen when the user recieves an email and they click on a link inside that email that link will contain all values necessaries to fill a cookie.

Basically I just need to create a test page, showing how it works.

I Need help creating a test scenario for what I need to do.

Appreciate your help,

Thanks
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747813
Ok, so back up a second.  Why do you need to put the variables in the querystring if you're setting a cookie?  That seems sorta backwards to me.

So, the link in the email will already have all the querystring values in it, right?  Why then are you trying to set up another querystring?

Maybe I am missing something.
0
 

Author Comment

by:vthunder70
ID: 24747844
YOu have no idea how much I appreciate you sticking around with me with this one.

I just started drawin the problem out and kind of realized the same thing you are saying.

I will assume that the user gets an emial with a list of products, and each product will have a like that will say something like "buy now" that link should have the cookie attached to the url like this:

http://blah.stores.yahoo.net/tholap.html?j=1018883&e=bloah.blah@blah.com&l=166265_HTML&u=10424764&mid=103148&jb=0

I hope this makes sense, I've been just trying to create something simar to that so that I can prove to my boss that is working.

Many thanks,
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747910
Ok, so then that URL is in the browser after the user clicks the link in the email, right?  Then what?  You want to parse that URL and set a bunch of cookies?  Why do you want to do that?
0
 

Author Comment

by:vthunder70
ID: 24747930
So that Yahoo! stores knows exactly where to go and who the visitor is. and maybe speed up on the check out process
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747970
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747971
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747972
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747973
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747974
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747977
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747978
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747979
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747980
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747981
Ok, so unless I'm missing something, you're pretty much there.

When you land on whatever page has your JS function, the URL will contain all those values that you suggest.  You then call your JS function to set the cookies.  Then, ANYTHING that takes you to another page should work.  Just stick a link on a page (see code).

Then, create a myNextPage.html.  You don't even have to put anything on it.  Just check a cookie inspector in FireFox or something to make sure that the cookies are set properly.

Once you grab the values out of the email URL and set the cookies, you're all set.  You don't have to submit any forms or do any redirects.  The cookies will be there in the browser session.
<html>
<head>
//set cookie code:
<script language="javascript">
 
//Set the number of days before your cookie should expire
var ExpireDays = 30;
 
//Set the cookie
qstr = document.location.search;
qstr = qstr.substring(1,qstr.length)
function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
   }
   
   thevars = qstr.split("&");
        for(i=0;i<thevars.length;i++) {
               thecase=thevars[i].split("=")
               switch(thecase[0]) {
                                case "e":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("EmailAddr",e,ExpireDays);
                                        break;
                                case "j":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("JobID",j,ExpireDays);
                                        break;
                                case "l":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("ListID",l,ExpireDays);
                                        break;
                                case "jb":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("BatchID",jb,ExpireDays);
                                        break;
                                case "u":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("UrlID",u,ExpireDays);
                                        break;
                                case "mid":
                                        thevars[i] = thevars[i].replace("=","='")+"'";
                                        eval(thevars[i]);
                                        SetCookie("MemberID",mid,ExpireDays);
                                        break;
                                default:
                                        eval(thevars[i]);
                                        break;
                        }
}
 
</script>
 
 
//get cookie code
 
<script language="javascript">
 
//Retrieve the cookie
function getCookie(cookiename){
        if(document.cookie.length >0) {
                startC = document.cookie.indexOf(cookiename+"=");
                if (startC != -1) {
                        startC += cookiename.length+1;
                        endC = document.cookie.indexOf(";",startC);
                        if(endC ==-1) endC = document.cookie.length;
                                return unescape(document.cookie.substring(startC, endC));
                                }
                        }
                return null;
        }
        
var jobid = getCookie("JobID");
var emailaddr = getCookie("EmailAddr");
var listid = getCookie("ListID");
var batchid = getCookie("BatchID");
var urlid = getCookie("UrlID");
var memberid = getCookie("MemberID");
 
</script>
</head>
<body>
<a href="myNextPage.html">Click me</a>
</body>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24747984
sometimes EE likes to post answers 15,000 times.  no clue why.
0
 

Author Comment

by:vthunder70
ID: 24748293
haha noprblem, thanks.

so I still need to get my links to be formatted like this


http://thermacell.stores.yahoo.net/tholap.html?j=1018883&e=randy.marquis@pursuitconsulting.com&l=166265_HTML&u=10424764&mid=103148&jb=0

for what I can see the function sets all those variables (j,e,l,u,mid and jb) how do I append those into link.

The link must contain that information once the user clicks on it.

Thanks, again!
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24748344
I thought the link was already generated in the email.  What link are you talking about?
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24748374
So, the user gets an email that has a link in it ("when a user clicks on a link that will be inside an email it will redirectem to a page with all the values of the cookie attached to the querystring").  To me, that means that there's a link in the email that looks like this:

http://thermacell.stores.yahoo.net/tholap.html?j=1018883&e=randy.marquis@pursuitconsulting.com&l=166265_HTML&u=10424764&mid=103148&jb=0

Then, that takes you to this page we're talking about, where you parse the querystring, assign all that stuff to cookies, then reassemble the URL and attach it to a new link on the page.

Why on earth would you want to do that?  You have the URL, so why disassemble it and then reassemble it?

Am I losing my mind here?
0
 

Author Comment

by:vthunder70
ID: 24748473
OHHHHHHHHHH NOOOOOOOO!!

Ok so since I lost my mind a long time ago and I realize you are losing yours while trying to help me ( much much much appreciated!!!!) I just went over to talk to the project manager and apparently what my other co-worker told me is wrong.

we have a template-top.asp that works as an include file for the top navigation of that site. In that include file we add the javascript and any link clicked from THE SITE (NO EMAIL i'm soooo sorry for confusion) that goes to that store should have those cookies added to the querystring.

does it make sense now?

sooooo sorry for the misunderstanding, very frustrating
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24748617
Ok, so then I can assume that the cookies are set properly, yes?  You're just looking for a way to build the URL target of a link, given those values.  Is that correct?

So, on the HTML page, you do this (put the real URL in the formatURL function call, and let the JS function append all the querystring parameters).
<a onclick="formatURL('myDestinationPage');">Click Me</a>
 
<script>
function formatURL(targetURL)
{
  var newURL = formatURL + '&' + getCookie('JobID') + '&' + getCookie('EmailAddr') + '&' + getCookie('ListID') + '&' + getCookie('BatchID') + '&' + getCookie('UrlID') + '&' + getCookie('MemberID');
 
  window.location.replace(newURL);
}
</script>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24748618
Ok, so then I can assume that the cookies are set properly, yes?  You're just looking for a way to build the URL target of a link, given those values.  Is that correct?

So, on the HTML page, you do this (put the real URL in the formatURL function call, and let the JS function append all the querystring parameters).
<a onclick="formatURL('myDestinationPage');">Click Me</a>
 
<script>
function formatURL(targetURL)
{
  var newURL = formatURL + '&' + getCookie('JobID') + '&' + getCookie('EmailAddr') + '&' + getCookie('ListID') + '&' + getCookie('BatchID') + '&' + getCookie('UrlID') + '&' + getCookie('MemberID');
 
  window.location.replace(newURL);
}
</script>

Open in new window

0
 
LVL 9

Accepted Solution

by:
jmanGJHS97 earned 2000 total points
ID: 24748619
Ok, so then I can assume that the cookies are set properly, yes?  You're just looking for a way to build the URL target of a link, given those values.  Is that correct?

So, on the HTML page, you do this (put the real URL in the formatURL function call, and let the JS function append all the querystring parameters).
<a onclick="formatURL('myDestinationPage');">Click Me</a>
 
<script>
function formatURL(targetURL)
{
  var newURL = formatURL + '&' + getCookie('JobID') + '&' + getCookie('EmailAddr') + '&' + getCookie('ListID') + '&' + getCookie('BatchID') + '&' + getCookie('UrlID') + '&' + getCookie('MemberID');
 
  window.location.replace(newURL);
}
</script>

Open in new window

0
 

Author Comment

by:vthunder70
ID: 24748885
Ok so I think we are on the right path here.

but when I click on the link I get the followin error

Forbidden
You don't have permission to access /function formatURL(targetURL) { var newURL = formatURL + "&" + getCookie("JobID") + "&" + getCookie("EmailAddr") + "&" + getCookie("ListID") + "&" + getCookie("UrlID") + "&" + getCookie("MemberId") + "&" + getCookie("BatchId"); window.location.replace(newURL);}&null&null&null&null&null&null on this server.

and my address bar looks like this:
http://www.mosquitorepellent.com/function%20formatURL(targetURL)%20%7B%20%20%20%20var%20newURL%20=%20formatURL%20+%20%22&%22%20+%20getCookie(%22JobID%22)%20+%20%22&%22%20+%20getCookie(%22EmailAddr%22)%20+%20%22&%22%20+%20getCookie(%22ListID%22)%20+%20%22&%22%20+%20getCookie(%22UrlID%22)%20+%20%22&%22%20+%20getCookie(%22MemberId%22)%20+%20%22&%22%20+%20getCookie(%22BatchId%22);%20%20%20%20window.location.replace(newURL);}&null&null&null&null&null&null
0
 

Author Comment

by:vthunder70
ID: 24749102
Ok Ok Ok,

I just got back to chatting wiht my project manager again. this is the latest:

The customer will get an email that will redirect them to the companies website, once the user gets redirect from his/her email to the website, that's when the cookie variables will get populated.

and.. I believe after that happens your function will be able to work properly.

I think this makes a lot more sense now, and my last post wiht the error simply says that there is not value inside those variables, right? or is there  a syntax problem as well?

I will get back to you as soon as I get an email to test this with, should be early morning tomorrow.

Many many many thanks!!!!

and thanks for stickign around!

0
 

Author Comment

by:vthunder70
ID: 24749390
Great news,

I had to make some minor changes to your code and understood a little better what was going on. So I the information in the sample that Iposted with the question and it worked.

Now I jsut got to wait till tomorrow but I think I got it working.

Thanks and I'll let you know ASAP in the morning!!
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24749406
Yeah, you'll have to handle null cookie values.

No problem.  I hope this works for you.
<a onclick="formatURL('myDestinationPage');">Click Me</a>
 
<script>
function formatURL(targetURL)
{
  var newURL = formatURL;
  var jobid = getCookie("JobID");
  var emailaddr = getCookie("EmailAddr");
  var listid = getCookie("ListID");
  var batchid = getCookie("BatchID");
  var urlid = getCookie("UrlID");
  var memberid = getCookie("MemberID");
 
  if (jobid != null)
  {
    newURL = newURL + '&' + jobID;
  }
 
  if (emailaddr != null)
  {
    newURL = newURL + '&' + emailaddr;
  }
 
  if (listid != null)
  {
    newURL = newURL + '&' + listid;
  }
 
  if (batchid != null)
  {
    newURL = newURL + '&' + batchid;
  }
 
  if (urlid != null)
  {
    newURL = newURL + '&' + urlid;
  }
  
  if (memberid != null)
  {
    newURL = newURL + '&' + memberid;
  }
 
  window.location.replace(newURL);
}
</script>

Open in new window

0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24749424
Cool, glad to hear it.
0
 

Author Closing Comment

by:vthunder70
ID: 31598414
Thanks alot for your help!!

It works great, I got the test email and the cookie gets set from the email allowing me to use those values later for my new links

txs,
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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

927 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