FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Cookies with Javascript

 


roeenoy228
How can i work with cookies and javascript?

which options can i do?
Are there ways to get information about cookies?


thanks,
roee
MrBlueSky
To read the cookie that belongs to te current page, use document.cookie.

Try it: type this in the URL bar of your browser:

Code:

javascript:alert(document.cookie)


A popup will show you the contents of your frihost-cookie.

To store a value in the cookie, simply assign to the document.cookie property:

Code:

document.cookie = "message=hello"


That's all. Although this sounds simple, it is a tedious method to read and write cookies: you will have to parse the cookie contents into key-value pairs. For more information on how to handle cookies with javascript, see: http://applex.frontsea.com/smb/oreilly/books/webdev/jscript/ch15_01.html

Or, a simpler explanation: http://www.w3schools.com/js/js_cookies.asp

The best way to deal with cookies is to write a class or some functions which handle all the administration for you. A good example of such a class: http://applex.frontsea.com/smb/oreilly/books/webdev/jscript/ch15_05.html
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.