Sunday, February 21, 2010

How to dynamically display the content of your Cookie using Javascript?

Almost the same as the previous post. Just need to replace the cookie variable in the assignment of innerHTML.

<span id="myHTML"></span>

document.getElementById('myHTML').innerHTML = document.cookie.indexOf("myCookieName");   // where 'myCookieName' is the name of the cookie such as the shopping cart item quantity, etc..

You can set up a Javascript function to handle this dynamic capability and receive event calls from omouseover, onload, ... HTML event as a trigger to the change of content. You can also set up a timer to change the content periodically.

No comments:

Post a Comment