|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cookies and Javascript.
I'm trying to figure how javascript handles cookies. Here are my questions:
- Is it possible for a javascript to read a cookie that was set trough php? - How do you set a cookie in javascipt? Is there an aquivalent of the php function setcookie() ? How do you read cookies with javascript? I know in php you just type a variable wich is the name of the cookie, is it the same in JS? Finaly, if someone know a good, complete tutorial on cookies with JS, please tell me! Thanks |
|
#2
|
||||
|
||||
|
Yes, javascript and php and asp and any cookies are interchangable, readable and settable by every language.
javascript: document.cookie = "cookiename=cookievalue" In javascript the retrieving of cookies is a bit difficult. What you actually get returned is a string representing every cookie. So to extract cookie info you need to substring it as such: var cookieVal = document.cookie.substring(document.cookie.indexOf("cookiename") + 11, document.cookie.length) Yup, it's crap, so you're better off using PHP/ASP to extract the cookie info. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Cookies and Javascript. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|