Tutorijali.Net forum
Promjena cookies-a - Printable Version

+- Tutorijali.Net forum (http://www.tutorijali.net/forum)
+-- Forum: Izrada weba (/forumdisplay.php?fid=5)
+--- Forum: Javascript (/forumdisplay.php?fid=7)
+--- Thread: Promjena cookies-a (/showthread.php?tid=1054)



Promjena cookies-a - zero - 12-11-2008 12:27 PM

Moze li se vec napravljeni cookies editirati? Imam sljedeci kod:
Code:
<html>
<head>
<style type="text/css">
#dolje
{
text-align: center;
max-width: 300px;
}

#copyright
{
font-align: center;
font-size: 10pt;
font-weight: bold;
}

BODY
{
COLOR: #000;
font-size:10pt;
background:#FFF;
margin: 0px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}

#ltop1 {position:relative; width:100%; min-width:980px; height:100px; z-index:2; background-image:url(mp.gif); background-repeat:repeat-x; left:0px; top:0px;}
</style>
</head>
<body>
<center>
<div id="ltop1">&nbsp;</div>
<script language="JavaScript">
<!--

function set_cookie ( name, value, expires_year, expires_month, expires_day, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( expires_year )
  {
    var expires = new Date ( expires_year, expires_month, expires_day );
    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;

}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

if ( ! get_cookie ( "biljeske" ) )
{
  var biljeske = prompt ("Upisite biljeske", "" );

  if ( biljeske )
  {
    var current_date = new Date;
    var cookie_year = current_date.getFullYear ( ) + 1;
    var cookie_month = current_date.getMonth ( );
    var cookie_day = current_date.getDate ( );
    set_cookie ( "biljeske", biljeske, cookie_year, cookie_month, cookie_day );
    document.location.reload( );
  }
}
else
{
  var biljeske = get_cookie ( "biljeske" );
  document.write("Evo vasih biljeska: <br />"+ biljeske +"<br /><br /><a href=\"javascript:delete_cookie('biljeske'); document.location.reload( );\">Pobrisi biljeske</a>" );
}

// -->
</script>
<div id="dolje">
<div id="copyright">
Copyright© by zero
</div>
</div>
</center>
</body>
</html>
Kao sto vidite, ovdje mozete upisati biljesku u cookie. Kako sada taj cookie, tj. biljesku promjeniti?


RE: Promjena cookies-a - Puž - 12-11-2008 10:03 PM

Pa sam pozoves set_cookie funckiju proslijedis koji string kolac treba bit i i to je to....

Code:
set_cookie ( "biljeske", "nova vrijednost", "2008", "12", "1");

Al preporučal bi ti da takve stvari radiš sa JQuery-em... Manje koda, lakše i tak... Skini ova dva fajla i ubaci ih unutra:
Code:
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
I ovak kodiraš skriptu:
Code:
$.cookie("Bilješke","Vrijednost");//Napraviš kolač
$.cookie("Bilješke","Vrijednost 2");//Editaš kolač sa novom vrijednosti
$.cookie("Bilješke",null);//Zbrišeš kolač



RE: Promjena cookies-a - zero - 13-11-2008 01:43 PM

Thx a lot puz. Imam jos jedan problem. Kako kao value u text box staviti ovu vrijednost cookia?