Link to home
Start Free TrialLog in
Avatar of mattjulius
mattjulius

asked on

using javascript cookie in coldfusion?

Hi There! I'm angelo and i want to ask if its possible to use or retrieve javascript cookie using coldfusion cfcookie and and if i use javascript cookie can the form access it as soon as i've put value on it ?
Thanks.....
Avatar of pinaldave
pinaldave
Flag of India image

Yes it is possible and valid.
Cookies are cookies in any languages.
1) Make sure that they are setting them in the same domain and everything is fine.
If they are cross domain things are complicated but can be done!
Regards,
--Pinal
Avatar of andw928
andw928

It is possible to retrieve a javascript cookie using Coldfusion, since all cookies are written to your browser's cookies.txt file, no matter what language you use. You may access the cookie right away using javascript IF and ONLY if you have created it with javascript. You may not access a cookie on the same page if it was created using javascript and accessed via Coldfusion, that will not work. It will also not work if you create a cookie using Coldfusion and try to access it via javascript on the same page.

Although, if the same langauge that accesses the cookie, is the one that sets it on that same request, then yes the same language can access it. The key thing to remember here, is that you can't create and access a cookie with 2 different languages on the same page request, although you may retrieve the cookie with different languages but only on a second page request.
Avatar of mattjulius

ASKER

how?
how can I use javascript cookie in coldfusion?
This is how you can set cookies using Javascript :
http://www.javascripter.net/faq/settinga.htm

This is how you can read cookies using ColdFusion:
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-a18.htm#wp1097825

I am not copy pasting the answer as it would not be appropriate. There is detail answer to your question with example in above mentioned link:
Regards,
---Pinal

I know how to read cookie but what i'm asking is how can i retrieve a javascript cookie?
should i convert it to coldfusion parameter, HOW!
Cookies are property of Browser, not ColdFusion or Javascript.
The cookies are same for both the language. It is like you are accessing .php or .cfm from browser, what you really see is html. This is similar situation. You just set the cookies in JS and you can read the cookie of JS the same way you read in CF you do not need to convert anything. If you store the cookie using JS as "myCookie" using the example link which I provided, you can read the same cookie in coldfusion using the variable #cookie.myCookie#  you do not have to do anything here.
Regards,
---Pinal
I tried what you  are saying but it looks like cfcookie doesn't find #cookie.myCookie# or #mycookie#!
they will. As it is said before you need to use the same browser and cookies are suppose to set first and then in the next template they should be read. Are you trying that way?
Yes, actually i'm working on it now and thanks for your time if only i have better points now i'll give to you and base on your suggestion can you give me. the code....thanks and god bless you for your effort to help others....
Yes I did it thank you very much and can you me your email just send it to <email address removed by pinaldave CF page Editor> ......someday god will bless you for effort of helping others.....
by the way can i pass javascript cookie directly to cfcookie value.....?
ASKER CERTIFIED SOLUTION
Avatar of pinaldave
pinaldave
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial