IT Community - Software Programming, Web Development and Technical Support

Creating Cookies

This is a discussion on Creating Cookies within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; how can i create a cookie in java script? i basically want a function that does the equivilant of this ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-24-2007, 01:02 AM
pranky pranky is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 51
pranky is on a distinguished road
Default Creating Cookies

how can i create a cookie in java script? i basically want a function that does the equivilant of this in php
Code:
PHP Code:
setcookie('clicked', "TRUE", time()+99999) 
what i intend is to have a link, and when it is clicked, the javascript create a cookie
Code:
HTML Code:

<a href="http://www.google.com" onclick"CookieClick()">gooooogle</a>
or something like that

CookieClick() would then create the cookie
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-21-2007, 03:06 AM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Creating Cookies

Hi
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
var cookie_string = name + "=" + escape ( value );

if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}

if ( path )
cookie_string += "; path=" + escape ( path );

if ( domain )
cookie_string += "; domain=" + escape ( domain );

if ( secure )
cookie_string += "; secure";

document.cookie = cookie_string;
}

set_cookie ( "username", "John Smith", 2003, 01, 15 );


Try like this
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-21-2007, 05:02 AM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Re: Creating Cookies

Creating Cookies

Example of Creating cookie:

<html>
<body>
<script language="JavaScript">
myDate = new Date('12/22/2010 12:00 AM');
document.cookie = 'firstName=xxx;
expires=' + myDate.toString + ';';
</script>
<button onclick="alert(document.cookie);">Example of Cookie</button>
</body>
</html>

ThankQ

KiruthikaSambandam
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/html-css-javascript-coding-techniques/263-creating-cookies.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 11-21-2007 09:09 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Games aicram Game Development 5 11-05-2008 08:41 PM
Cookies nhoj Java Server Pages (JSP) 4 09-29-2008 12:32 AM
PDF Creating in PHP saravanan PHP Programming 20 04-08-2008 07:15 AM
Creating password chocoguy Perl 0 01-01-2008 12:53 AM
Cookies ragavraj PHP Programming 4 11-01-2007 12:48 PM


All times are GMT -7. The time now is 09:18 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0