javascript / jquery cookies -


did knows how create cookie , value? have list hyperlink , dont know use cookie javascript or jquery.

this example hyperlink

<ul>  <li><a href="home">home</a></li>  <li><a href="about_me">about me</a></li>  <li><a href="reference">reference</a></li>  <li><a href="contact">contact</a></li> </ul> 

if user click on about_me or reference cookies chould remembered. thank kind of help.

if want via jquery need add 1 library of jquery jquery.cookie.js

and put code below: $(document).ready(function(){ $("ul > a").click(function(){ // set cookie. $.cookie('hrefatt', $(this).attr(href)); }); }) if need via javascript : create function below function setcookie(cookiename,cookieval,expires) { document.cookie = cookiename+ "=" + cookieval+ "; " + expires; }

and call function below:

   <ul>         <li><a href="home" onclick="setcookie('hrefcookie','home',1)">home</a>           </li>          <li><a href="about_me" onclick="setcookie('hrefcookie','about_me',1)">about me</a></li>          <li><a href="reference" onclick="setcookie('hrefcookie','reference',1)">reference</a></li>         <li><a href="contact" onclick="setcookie('hrefcookie','contact',1)">contact</a></li>        </ul>       </pre> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -